-
-
Save kikmedia/f5dee67958735a1cc2add2f54c6c288e to your computer and use it in GitHub Desktop.
Contao 4.8.0 DB Migration wichtiger Teil eines Bildes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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