-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FIX 16.0 - $object->updateCommon($user) = loss of fk_user_author
#28526
FIX 16.0 - $object->updateCommon($user) = loss of fk_user_author
#28526
Conversation
I pushed a different patch to fix this: 284fb49 |
It doesn't seem to fix the problem: when I re-ran my test after pulling 16.0, I obtained the same results as before : NULL, 1, 0 instead of 1, 1, 1. |
The first var_dump($p->user_creation_id); |
I still get NULL, 1, 0 instead of 1, 1, 1. |
NULL, 1, 0 is result for your sample test. But what do you have if you add |
Sorry for my previous answer: it was incomplete and out of context. I also realize there are problems with both my initial test case and my attempted fix, which made things confusing. In fact there are two problems, which are related but which call for distinct fixes. Problem 1The first problem is that after calling
Problem 2The second problem is that after calling
Updated test caseHere is an updated test case: it tests 4 cases:
Each test has 3 sub-tests:
require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php';
require_once DOL_DOCUMENT_ROOT . '/knowledgemanagement/class/knowledgerecord.class.php';
$TestResults = [];
$numTest = 1;
$langs->loadLangs(array('main', 'errors', 'knowledgemanagement', 'ticket', 'other'));
$db->begin();
$user->fetch(1);
// TEST USING A CORE CLASS CREATED WITH MODULEBUILDER
$object = new KnowledgeRecord($db);
$object->question = 'test';
$object->create($user);
$obj = $db->getRow('SELECT rowid, fk_user_creat FROM ' . $db->prefix() . $object->table_element . ' WHERE rowid = ' . $object->id);
$TestResults['TEST ' . $numTest++ . ' (CommonObject::createCommon)'] = [
'$object->fk_user_creat == 1' => $object->fk_user_creat == 1,
'$object->user_creation_id == 1' => $object->user_creation_id == 1,
'$obj->fk_user_creat == 1' => $obj->fk_user_creat == 1
];
$object->update($user);
$obj = $db->getRow('SELECT rowid, fk_user_creat FROM ' . $db->prefix() . $object->table_element . ' WHERE rowid = ' . $object->id);
$TestResults['TEST ' . $numTest++ . ' (CommonObject::updateCommon)'] = [
'$object->fk_user_creat == 1' => $object->fk_user_creat == 1,
'$object->user_creation_id == 1' => $object->user_creation_id == 1,
'$obj->fk_user_creat == 1' => $obj->fk_user_creat == 1
];
// TEST USING A CORE CLASS NOT CREATED WITH MODULEBUILDER
$p = new Product($db);
$p->ref = 'test';
$p->type = 0; // produit
$p->label = 'test';
$p->entity = 1;
$id = $p->create($user);
$obj = $db->getRow('SELECT rowid, fk_user_author FROM ' . $db->prefix() . $p->table_element . ' WHERE rowid = ' . $p->id);
$TestResults['TEST ' . $numTest++ . ' (Product::create)'] = [
'$p->user_creation_id == 1' => $p->user_creation_id == 1,
'$p->fk_user_creat == 1' => $p->fk_user_creat == 1,
'$obj->fk_user_author == 1' => $obj->fk_user_author];
$p->update($p->id, $user);
$obj = $db->getRow('SELECT rowid, fk_user_author FROM ' . $db->prefix() . $p->table_element . ' WHERE rowid = ' . $p->id);
$TestResults['TEST ' . $numTest++ . ' (Product::update)'] = [
'$p->user_creation_id == 1' => $p->user_creation_id == 1,
'$p->fk_user_creat == 1' => $p->fk_user_creat == 1,
'$obj->fk_user_author == 1' => $obj->fk_user_author];
echo json_encode($TestResults, JSON_PRETTY_PRINT);
$db->rollback(); These are the results with today's 16.0.
{
"TEST 1 (CommonObject::createCommon)": {
"$object->fk_user_creat == 1": true,
"$object->user_creation_id == 1": false,
"$obj->fk_user_author == 1": true
},
"TEST 2 (CommonObject::updateCommon)": {
"$object->fk_user_creat == 1": true,
"$object->user_creation_id == 1": false,
"$obj->fk_user_author == 1": true
},
"TEST 3 (Product::create)": {
"$p->user_creation_id == 1": false,
"$p->fk_user_creat == 1": false,
"$obj->fk_user_author == 1": "1"
},
"TEST 4 (Product::update)": {
"$p->user_creation_id == 1": false,
"$p->fk_user_creat == 1": false,
"$obj->fk_user_author == 1": "1"
}
} Solutions / ideas
I'll try to update my PR accordingly. |
Sorry, I again made a mistake: I thought that ModuleBuilder created a database column named I'm updating the test case in my previous comment. |
About your test, it miss an important information. the field ->xxx for user creation must be filled in memory like it is after the create (because it is defined by the create itself), but only if the property has been defined on the class. In v16, there is a lot of object than as only 1 among the 3 property. So can you must the test to say on which object you did the test because result may differ. |
I am closing my PR because the main problem has been fixed, and the remaining improvements will be better treated in individual PRs: this will save everyone from having to read my lengthy and mostly pointless comments. 📚 |
FIX fk_user_author lost when calling updateCommon()
When
createCommon()
is called, the database columnfk_user_author
is correctly set using$user->id
, but the object's field in memory (which, unfortunately, is named differently, namely `user) does not reflect that and remains NULL.When
updateCommon()
is called, it uses setSaveQuery(), which sets the database columnfk_user_author
to 0 because $this->fk_user_author isn't set. Even ifuser_creation_id
were correctly set, the naming difference would still causefk_user_author
to be updated to 0.Here is a minimalist reproduction case:
I am not sure that my fix is the right way of fixing the problem because I am not sure whether updateCommon() should or shouldn't modify fk_user_author if
user_creation_id
has been changed on the object. I assumed it should not be changed.I also haven't investigated whether other fields with a naming difference between database column and the corresponding CommonObject field have a similar problem.