[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
committed by Diogo Peralta Cordeiro
parent 346aec9b2a
commit b1b1d2af93
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();
}
}