Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // This script get a dates of albums from Gallery2 SQL DB
- // and touches every dir/album in destination folder.
- // Useful within G2-Piwigo process.
- // 1. copy directories from G2 data/albums to piwigo/galleries
- // 2. run this script with only_list=true, it will show you
- // 3. run this script with only_list=false, it will touch dirs
- // It will only change a metadata (mtime and ctime) of directories
- // and only if they will be founded in G2 table.
- $root = '/dir/to/galleries';
- $only_list = true;
- mysql_connect("localhost", "g2-username", "g2-pass") or die(mysql_error());
- mysql_select_db("database_name") or die(mysql_error());
- mysql_query("SET NAMES 'utf8'");
- mysql_query("SET CHARACTER SET utf8 ");
- $query = 'SELECT g2_Item.g_id as id,
- g2_Item.g_title as title,
- g2_Item.g_originationTimestamp as timestamp,
- g2_Item.g_originationTimestamp as date,
- g2_FileSystemEntity.g_pathComponent as directory,
- g2_ItemAttributesMap.g_parentSequence as parent
- FROM g2_Item,g2_FileSystemEntity,g2_ItemAttributesMap
- WHERE g2_Item.g_canContainChildren=1 and
- g2_FileSystemEntity.g_id=g2_Item.g_id and
- g2_ItemAttributesMap.g_itemId=g2_Item.g_id
- ORDER BY id';
- $result = mysql_query($query);
- while($row = mysql_fetch_array($result, MYSQL_ASSOC))
- {
- if ($row["directory"] != '') {
- if ($only_list) { echo "$row[id] | $row[title] | " . date('r', $row["date"]) . " | "; }
- $path = '';
- $entity = $row["id"];
- $end = 'false';
- while ($end == 'false') {
- $query2 = "SELECT g2_FileSystemEntity.g_pathComponent as parentDirectory,
- g2_ChildEntity.g_parentId as parentId
- FROM g2_FileSystemEntity,g2_ChildEntity
- WHERE g2_ChildEntity.g_id='$entity' and
- g2_ChildEntity.g_parentId=g2_FileSystemEntity.g_id";
- $result2 = mysql_query($query2);
- $num_rows = mysql_num_rows($result2);
- switch ($num_rows) {
- case 0:
- $end = 'true';
- break;
- case 1:
- $row2 = mysql_fetch_array($result2);
- $entity = $row2["parentId"];
- $path = $row2["parentDirectory"] . '/' . $path;
- break;
- default:
- echo "error - too much rows ($num_rows) ";
- $end = 'true';
- }
- }
- $fullpath = $path . $row["directory"];
- if ($only_list) {
- echo $fullpath . "\n";
- } else {
- if (is_dir($root . $fullpath))
- {
- echo 'Touching ' . $root . $fullpath . "\n";
- touch($root.$fullpath, $row["date"]);
- } else {
- echo 'Missing directory ' . $root . $fullpath . "\n";
- }
- }
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement