Change assignments without losing data
Created 1 year ago by pooria

Hi

After long days of investigating Pyrocms It's become really a friend to me and now I understand its magic. But one of pyrocms's problems is that users module is not translatable by default. How can I make this module translatable? Should I create a new translation table manually?

I tried this:

$stream = $this->streams()->findBySlugAndNamespace('users', 'users');
$stream->setAttribute('translatable', true)
             ->save();

But I get this error:

SQLSTATE[42S02]: Base table or view not found: 1146 Table 'facpyro.default_users_users_translations' doesn't exist (SQL: select * from `default_users_users_translations` where `default_users_users_translations`.`entry_id` = 1 and `default_users_users_translations`.`entry_id` is not null)
pooria  —  1 year ago Best Answer

I found the problem. The problem is in Illuminate\Auth\EloquentUserProvider. and method:

public function retrieveById($identifier)
    {
        $model = $this->createModel();

        return $model->newQuery()
            ->where('users_users.' . $model->getAuthIdentifierName(), $identifier)
            ->first();
    }

I added 'users_users.' . before $model->getAuthIdentifierName() And the problem is gone.

Also I deleted display_name, first_name and last_name columns from users_users and cleared website's cookies.

Thanks @ryanthompson

ryanthompson  —  1 year ago

Hmm so it isn't! Can I ask what your use case is?

One or two big things are left in the magic hat of DB management from Streams changes. Both related to translations! You can definitely manually do this though you just need to make the translations table manually. Then compile and you should be able to mark assignment translatable at that time.

pooria  —  1 year ago

@ryanthompson Hi Ryan. I want to translate display_name. The same author posts in both English and Persian so I need to translate his name. The manual work is cumbersome btw 😄

P.S: I'm sorry I can't contact you in Slack because sadly Slack has blocked Iranian users and VPNs are really slow 🙍

ryanthompson  —  1 year ago

I will make users translatable going forward. But for backwards compatible instances, this manual method will need to suffice until I get a better system in place to automate it :-/

pooria  —  1 year ago

@ryanthompson Thanks Ryan 😄

pooria  —  1 year ago

@ryanthompson

It got messed up 🙍 I changed the translatable column to 1 in default_streams_streams table, users row. And also changed the corresponding translatable columns of display_name, first_name, last_name of default_streams_assignments. I also created the default_users_users_translations table. But now I'm getting this:

SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'id' in where clause is ambiguous (SQL: select `default_users_users`.* from `default_users_users` left join `default_users_users_translations` on `default_users_users`.`id` = `default_users_users_translations`.`entry_id` where `id` = 1 and (`default_users_users_translations`.`locale` = fa or `default_users_users_translations`.`locale` = en or `default_users_users_translations`.`locale` is null) and `default_users_users`.`deleted_at` is null group by `default_users_users`.`id` order by `default_users_users_translations`.`display_name` asc limit 1)
ryanthompson  —  1 year ago

What's your query? Or is this just during a page load?

pooria  —  1 year ago

@ryanthompson during all page loads

ryanthompson  —  1 year ago

Try and find the code causing the query.. Not sure at this moment a quick work around.

pooria  —  1 year ago Best Answer

I found the problem. The problem is in Illuminate\Auth\EloquentUserProvider. and method:

public function retrieveById($identifier)
    {
        $model = $this->createModel();

        return $model->newQuery()
            ->where('users_users.' . $model->getAuthIdentifierName(), $identifier)
            ->first();
    }

I added 'users_users.' . before $model->getAuthIdentifierName() And the problem is gone.

Also I deleted display_name, first_name and last_name columns from users_users and cleared website's cookies.

Thanks @ryanthompson