[TYPO3-german] files und folders mit Unterordnern , 7.6.9
Renzo Bauen
typo3 at conpassione.ch
Fri Aug 12 23:25:49 CEST 2016
Uups, na kann ja nichts anhängen....
Hier der Code:
====================================================================================================================================
#!/user/bin/php
<?php
/*
* utility to update TYPO3 db-table 'sys_file'
* if the file- and directory-names in sys_file db-table all are
lowercase but
* not in the filesystem, then you need to run this script!
* DO NOT run the reindexing from TYPO3 BE prior to this script!!
* Reindexing will doublicate each file in the sys_file table!
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* Author: Renzo Bauen
* From: conPassione gmbh, info at conpassione.ch
*
* To run this script adjust the global variables ($server ...), then
run it from the commandline
* #>php ChangeSysFileToRealNames.php
*
* For debugging purpose you might uncomment some echoed lines
*/
$Server = 'localhost';
$DB = 'myprojectdb';
$DBuser = 't3user';
$DBpw = '1234';
$baseDir = '/var/www/myproject';
function updateFileInfo ($dir, $file, $conn) {
// format for field identifier:
// relative Path from Website-Root Directory or fileadmin + file +
fileext
// examples: '/uploads/myext/myfile.txt' or in fileadmin
'/templates/Resources/Public/Icons/myIcon.ico'
// function sha1 used to create hash
$newIdentifierName = ltrim($dir . "/" . $file,'.');
$identifier = '/' . ltrim($newIdentifierName, '/');
// format for field folder:
// examples: '/uploads/myext/' or in fileadmin
'/templates/Resources/Public/Icons/'
// function sha1 used to create hash
$newFolderName = ltrim($dir,'.');
// format for name (file): exact the same as identifier
// sha1_file used to create hash
echo "identifier: " . $identifier . " -> identifier_hash = " .
sha1($identifier) . "\n";
echo "folder: " . $newFolderName . " -> folder_hash = " .
sha1($newFolderName) . "\n";
echo "name: " . $identifier . " -> sha1 = " . sha1_file('.' .
$identifier) . "\n";
$sql = '';
$sql .= "Update sys_file set ";
$sql .= "`identifier`='" . $identifier . "', ";
$sql .= "`name`= '" . $file . "', ";
$sql .= "`identifier_hash` = '" .sha1($identifier) . "', ";
$sql .= "`folder_hash` = '" . sha1($newFolderName) . "', ";
$sql .= "`sha1` = '" . sha1_file('.' . $identifier) . "' ";
$sql .= "where `identifier`='" . strtolower($identifier) . "';";
echo "SQL: " . $sql . "\n\n\n";
if (mysqli_query($conn, $sql)) {
echo "OK\n";
} else {
echo "NOK: " . mysqli_error($conn) . "\n";
}
return 0;
}
function getDirs ($startDir, $conn) {
if (is_dir($startDir)) {
$myDir = array();
$myDir = scandir($startDir);
echo "\n";
foreach ($myDir as $myDirEntry) {
if (is_dir($startDir ."/" . $myDirEntry)) {
if (($myDirEntry<>'..') AND ($myDirEntry<>'.')) {
$tmp = getDirs($startDir ."/" . $myDirEntry, $conn);
}
} else {
updateFileInfo($startDir, $myDirEntry, $conn);
}
}
return 0;
} else
return 1;
}
echo "Start\n";
$DBconn = mysqli_connect($Server,$DBuser, $DBpw, $DB);
if ($DBconn) {
echo "Connection established\n";
} else {
die("Connection failed: " . mysqli_connect_error() . "\n");
}
$processDir = $baseDir . "/fileadmin";
chdir($processDir);
$relDir = ".";
echo "Process Files in " . $processDir . "\n";
$result = getDirs($relDir, $DBconn);
echo "Files in " .$processDir . " updated. Returncode: " .
$result ."\n";
$processDir = $baseDir . "/uploads";
chdir($baseDir);
$relDir = "./uploads";
echo "Process Files in " . $processDir . "\n";
$result = getDirs($relDir, $DBconn);
echo "Files in " .$processDir . " updated. Returncode: " .
$result ."\n";
mysqli_close($DBconn);
echo "End\n";
?>
====================================================================================================================================
Beste Grüsse, Renzo
--
conPassione gmbh
CH-3661 Uetendorf
+41 33 345 00 92
More information about the TYPO3-german
mailing list