Hello, i am experimenting
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1 Query: INSERT INTO gw6wm_template_overrides
during a complex extension update on joomla 4.
it seems that code in \plugins\installer\override\override.php
does "continue" when an update is detected but still allows to proceed with insert which gives the SQL error.
current code:
private function saveOverrides($pks)
{
// Insert columns.
$columns = [
'template',
'hash_id',
'action',
'created_date',
'modified_date',
'extension_id',
'state',
'client_id',
];
// Create an insert query.
$insertQuery = $this->db->getQuery(true)
->insert($this->db->quoteName('#__template_overrides'))
->columns($this->db->quoteName($columns));
foreach ($pks as $pk)
{
$date = new Date('now');
$createdDate = $date->toSql();
if (empty($pk->coreFile))
{
$modifiedDate = null;
}
else
{
$modifiedDate = $createdDate;
}
if ($this->load($pk->id, $pk->extension_id))
{
$updateQuery = $this->db->getQuery(true)
->update($this->db->quoteName('#__template_overrides'))
->set(
[
$this->db->quoteName('modified_date') . ' = :modifiedDate',
$this->db->quoteName('action') . ' = :pkAction',
$this->db->quoteName('state') . ' = 0',
]
)
->where($this->db->quoteName('hash_id') . ' = :pkId')
->where($this->db->quoteName('extension_id') . ' = :exId')
->bind(':modifiedDate', $modifiedDate)
->bind(':pkAction', $pk->action)
->bind(':pkId', $pk->id)
->bind(':exId', $pk->extension_id, ParameterType::INTEGER);
// Set the query using our newly populated query object and execute it.
$this->db->setQuery($updateQuery);
$this->db->execute();
continue;
}
// Insert values, preserve order
$bindArray = $insertQuery->bindArray(
[
$pk->template,
$pk->id,
$pk->action,
$createdDate,
$modifiedDate,
],
ParameterType::STRING
);
$bindArray = array_merge(
$bindArray,
$insertQuery->bindArray(
[
$pk->extension_id,
0,
(int) $pk->client,
]
)
);
$insertQuery->values(implode(',', $bindArray));
}
$this->db->setQuery($insertQuery);
$this->db->execute();
}
possible fix:
private function saveOverrides($pks)
{
// Insert columns.
$columns = [
'template',
'hash_id',
'action',
'created_date',
'modified_date',
'extension_id',
'state',
'client_id',
];
// Create an insert query.
$insertQuery = $this->db->getQuery(true)
->insert($this->db->quoteName('#__template_overrides'))
->columns($this->db->quoteName($columns));
foreach ($pks as $pk)
{
$date = new Date('now');
$createdDate = $date->toSql();
if (empty($pk->coreFile))
{
$modifiedDate = null;
}
else
{
$modifiedDate = $createdDate;
}
if ($this->load($pk->id, $pk->extension_id))
{
$updateQuery = $this->db->getQuery(true)
->update($this->db->quoteName('#__template_overrides'))
->set(
[
$this->db->quoteName('modified_date') . ' = :modifiedDate',
$this->db->quoteName('action') . ' = :pkAction',
$this->db->quoteName('state') . ' = 0',
]
)
->where($this->db->quoteName('hash_id') . ' = :pkId')
->where($this->db->quoteName('extension_id') . ' = :exId')
->bind(':modifiedDate', $modifiedDate)
->bind(':pkAction', $pk->action)
->bind(':pkId', $pk->id)
->bind(':exId', $pk->extension_id, ParameterType::INTEGER);
// Set the query using our newly populated query object and execute it.
$this->db->setQuery($updateQuery);
$this->db->execute();
continue;
}
// Insert values, preserve order
$bindArray = $insertQuery->bindArray(
[
$pk->template,
$pk->id,
$pk->action,
$createdDate,
$modifiedDate,
],
ParameterType::STRING
);
$bindArray = array_merge(
$bindArray,
$insertQuery->bindArray(
[
$pk->extension_id,
0,
(int) $pk->client,
]
)
);
$insertQuery->values(implode(',', $bindArray));
}
if (!empty($bindArray)) {
$this->db->setQuery($insertQuery);
$this->db->execute();
}
}
I do not know how to reproduce this exactly as i came on this one during intensive testing of other parts and extensions.
Best regards, stan
Labels |
Removed:
?
|
Labels |
Added:
No Code Attached Yet
|
The simplest fix is to check if we got any data to insert/update:
4.0-dev...stAn47:patch-2
The simplest fix is to check if we got any data to insert/update: 4.0-dev...stAn47:patch-2
@stAn47 Yes, you wrote that already in the description of the issue.
I think that beside the code style (it would need an empty line before the "if" condition and indentation by one tab more inside the "if" block) your fix is valid.
Do you want to make a pull request so you get the fame? Or shall I do it?
It could be a bit tricky with testing instructions. It would need to find out how to trigger the overrides update. I think it is cached somewhere for some time.
Hello Richard, pls do the pull request, i have no clue on how to do it and i don't need the fame, and i suggested the code by editing it directly at github here.
Yes, for testing i didn't really get that deep to find out how exactly to reproduce this, i just get it every other time i try to update an extension.
best regards, stan
I've found a way to reproduce it!
Status | New | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2021-10-28 12:19:47 |
Closed_By | ⇒ | richard67 |
the issue is still present in joomla 4.0.4, i do not know how to reproduce, but during updates of a 3rd party component extension, i get this issue once upon a while - after repeating the update, it is suddenly ok, so i guess the overrides are only checked "once upon a while" but the code itself is incorrect as it can do update/insert with empty datas which causes this error.