Skip to content

Instantly share code, notes, and snippets.

@BugBuster1701
Last active March 11, 2020 10:55
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save BugBuster1701/f6ee77eed5cc08896c900902729553ff to your computer and use it in GitHub Desktop.
Save BugBuster1701/f6ee77eed5cc08896c900902729553ff to your computer and use it in GitHub Desktop.
Contao 4.8.0 DB Migration wichtiger Teil eines Bildes
<?php
//ich muss ins web/ Verzeichnis, Aufruf über Browser oder Kommandozeile
//vorher DB Backup durchführen der tl_files Tabelle zur Sicherheit
define('TL_SCRIPT', 'MIGRATION480');
define('TL_MODE' , 'FE');
include __DIR__.'/../system/initialize.php';
use Contao\File;
$statement = Contao\Database::getInstance()->query('
SELECT
id, path, importantPartX, importantPartY, importantPartWidth, importantPartHeight
FROM
tl_files
WHERE
importantPartWidth > 1 OR importantPartHeight > 1
');
// im Original wurde hier mit >0 verglichen, >1 verhindert mehrfache Ausführung
$rootDir = Contao\System::getContainer()->getParameter('kernel.project_dir');
// Convert the important part to relative values as fractions
while (false !== ($file = $statement->fetchAssoc()))
{
if (!file_exists($rootDir.'/'.$file['path']) || is_dir($rootDir.'/'.$file['path']))
{
continue;
}
$imageSize = (new File($file['path']))->imageViewSize;
if (empty($imageSize[0]) || empty($imageSize[1]))
{
continue;
}
$stmt = Contao\Database::getInstance()->prepare('
UPDATE
tl_files
SET
importantPartX = ?,
importantPartY = ?,
importantPartWidth = ?,
importantPartHeight = ?
WHERE
id = ?
');
$stmt->execute(
$file['importantPartX'] / $imageSize[0],
$file['importantPartY'] / $imageSize[1],
$file['importantPartWidth'] / $imageSize[0],
$file['importantPartHeight'] / $imageSize[1],
$file['id']
);
}
echo "Fertich, theoretisch...";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment