[DATABASE] Update "modified" in Managed_DataObject instead of a DBMS trigger

Instead of relying on the MariaDB's ON UPDATE CURRENT_TIMESTAMP trigger update
"modified" attributes in Managed_DataObject. Every raw query that needs
adjusting is adjusted, as they won't update "modified" automatically anymore.

The main goal behind this change is to fix "modified" updates on PostgreSQL.
This commit is contained in:
Alexei Sorokin
2020-07-27 19:10:33 +03:00
parent 341f3d0ea5
commit ec86de2bc4
17 changed files with 224 additions and 140 deletions

View File

@@ -116,10 +116,15 @@ while ($fn->fetch()) {
echo " (unchanged, but embedding lookup failed)\n";
}
} elseif (!$dry) {
$sql = "UPDATE file " .
"SET mimetype=null, title=null,size=null,protected=null " .
"WHERE id={$f->id}";
$f->query($sql);
$f->query(sprintf(
<<<'END'
UPDATE file
SET mimetype = NULL, title = NULL, size = NULL,
protected = NULL, modified = CURRENT_TIMESTAMP
WHERE id = %d
END,
$f->getID()
));
$f->decache();
if ($data instanceof File_embed) {
$fetch = true;
@@ -144,12 +149,18 @@ while ($fn->fetch()) {
echo "Found broken file with ";
}
echo "ID: {$f->id}, URL {$f->url}\n";
echo "ID: {$f->getID()}, URL {$f->url}\n";
if (!$dry) {
$fetch = true;
$sql = "UPDATE file SET title=null, size=null, protected=null " .
"WHERE id={$f->id}";
$f->query($sql);
$f->query(sprintf(
<<<'END'
UPDATE file
SET title = NULL, size = NULL,
protected = NULL, modified = CURRENT_TIMESTAMP
WHERE id = %d,
END,
$f->getID()
));
$f->decache();
if ($data instanceof File_embed) {
@@ -159,7 +170,7 @@ while ($fn->fetch()) {
if ($thumb instanceof File_thumbnail) {
// Delete all thumbnails, not just this one
$f->query("DELETE from file_thumbnail WHERE file_id = {$f->id}");
$f->query("DELETE FROM file_thumbnail WHERE file_id = {$f->getID()}");
$thumb->decache();
}
}