$script = eZScript::instance(array("description" => "eZ Publish trashed images sanitizer script (#017781).", "use-session" => false, "use-modules" => false, "use-extensions" => true)); $script->startup(); $options = $script->getOptions("[n]", "", array("-q" => "Quiet mode", "n" => "Do not wait")); $script->initialize(); $cli = eZCLI::instance(); if (!isset($options['n'])) { $cli->warning("This cleanup script will remove any images from trashed objects."); $cli->warning("For more details about this cleanup, take a look at: http://issues.ez.no/17781."); $cli->warning(); $cli->warning("IT IS YOUR RESPONSABILITY TO TAKE CARE THAT NO ITEMS REMAINS IN TRASH BEFORE RUNNING THIS SCRIPT."); $cli->warning(); $cli->warning("You have 30 seconds to break the script (press Ctrl-C)."); sleep(30); } $fileHandler = eZINI::instance("file.ini")->variable("ClusteringSettings", "FileHandler"); $directory = eZSys::varDirectory() . "/storage/images"; switch (strtolower($fileHandler)) { case "ezfsfilehandler": case "ezfs2filehandler": array_map("filesystemCleanup", glob("{$directory}/*")); break; case "ezdbfilehandler": databaseCleanup($directory); break; case "ezdfsfilehandler": dfsCleanup($directory); break; default: $cli->error("Unsupported '{$fileHandler}' FileHandler."); } $script->shutdown();
function update() { global $cfg, $db, $lastGenre_id, $getID3, $dirsCounter, $filesCounter, $curFilesCounter, $curDirsCounter; authenticate('access_admin', false, true); require_once 'getid3/getid3/getid3.php'; require_once 'include/play.inc.php'; // Needed for mpdUpdate() $cfg['cli_update'] = false; $startTime = new DateTime(); $path = $cfg['media_dir']; $curFilesCounter = 0; $curDirsCounter = 0; $dirsCounter = 0; $filesCounter = 0; $prevDirsCounter = 0; $prevFilesCounter = 0; $dirs = array(); /* $objects = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path), RecursiveIteratorIterator::SELF_FIRST); foreach($objects as $name){ if ($name->isDir()) { ++$dirsCounter; } else { ++$filesCounter; } } */ //mysql_query('DELETE FROM genre'); //$lastGenre_id = 1; // formattedNavigator $nav = array(); $nav['name'][] = 'Configuration'; $nav['url'][] = 'config.php'; $nav['name'][] = 'Update'; require_once 'include/header.inc.php'; ?> <table width="100%" cellspacing="0" cellpadding="0" class="border"> <tr class="header"> <td class="space"></td> <td class="update_text">Update</td> <td>Progress</td> <td class="space"></td> </tr> <tr class="line"><td colspan="4"></td></tr> <tr class="odd"> <td></td> <td>Structure & image:</td> <td><span id="structure"></span></td> <td></td> </tr> <tr class="even"> <td></td> <td>File info:</td> <td><span id="fileinfo"></span></td> <td></td> </tr> <tr class="odd"> <td></td> <td>Cleanup:</td> <td><span id="cleanup"></span></td> <td></td> </tr> <tr class="even"> <td></td> <td>Update time:</td> <td><span id="updateTime"></span></td> <td></td> </tr> </table> <script> hideSpinner(); window.setInterval(function() { show_update_progress(); }, 500); function show_update_progress() { $.ajax({ type: "POST", url: "ajax-update-progress.php", dataType : 'json', success : function(json) { var s = json['structure_image']; if (s.indexOf("fa-spin") > -1) { if (!$("#structure").hasClass("fa-spin")) $("#structure").html(json['structure_image']); } else $("#structure").html(json['structure_image']); s = json['file_info']; if (s.indexOf("fa-spin") > -1) { if (!$("#fileinfo").hasClass("fa-spin")) $("#fileinfo").html(json['file_info']); } else $("#fileinfo").html(json['file_info']); s = json['cleanup']; if (s.indexOf("fa-spin") > -1) { if (!$("#cleanup").hasClass("fa-spin")) $("#cleanup").html(json['cleanup']); } else $("#cleanup").html(json['cleanup']); $("#updateTime").html(json['update_time']); } }); } </script> <?php @ob_flush(); flush(); $cfg['footer'] = 'dynamic'; require 'include/footer.inc.php'; $getID3 = new getID3(); //initial settings for getID3: include 'include/getID3init.inc.php'; $result = mysql_query('SELECT * FROM update_progress'); if (mysql_num_rows($result) == 0) { mysql_query('INSERT INTO update_progress (update_status, structure_image, file_info, cleanup, update_time, last_update) VALUES ("0", "", "", "", "", "")'); $update_status = 0; } else { $row = mysql_fetch_assoc($result); $update_status = $row["update_status"]; } if ($update_status != 1) { mysql_query("update update_progress set \n\t\t\tupdate_status = 1,\n\t\t\tstructure_image = '',\n\t\t\tfile_info = '',\n\t\t\tcleanup = '',\n\t\t\tupdate_time = '',\n\t\t\tlast_update = 'Update in progress..'"); //@ob_flush(); //flush(); mysql_query("update update_progress set \n\t\t\tstructure_image = 'Requesting MPD update...'"); mpdUpdate(); //@ob_flush(); //flush(); mysql_query("update update_progress set \n\t\t\tstructure_image = '<i class=\"fa fa-cog larger icon-selected fa-spin\"></i>'"); // Short sleep to prevent update problems with a previous update process that has not stopped yet. sleep(1); $cfg['new_escape_char_hash'] = hmacmd5(print_r($cfg['escape_char'], true), file_get_contents(NJB_HOME_DIR . 'update.php')); $cfg['force_filename_update'] = $cfg['new_escape_char_hash'] != $cfg['escape_char_hash'] ? true : false; $cfg['force_filename_update'] = false; if ($cfg['image_size'] != NJB_IMAGE_SIZE || $cfg['image_quality'] != NJB_IMAGE_QUALITY) { mysql_query('TRUNCATE TABLE bitmap'); mysql_query('UPDATE server SET value = "' . mysql_real_escape_string(NJB_IMAGE_SIZE) . '" WHERE name = "image_size" LIMIT 1'); mysql_query('UPDATE server SET value = "' . mysql_real_escape_string(NJB_IMAGE_QUALITY) . '" WHERE name = "image_quality" LIMIT 1'); } mysql_query('UPDATE album SET updated = 0'); mysql_query('UPDATE track SET updated = 0'); mysql_query('UPDATE bitmap SET updated = 0'); mysql_query('UPDATE genre SET updated = 0'); mysql_query('UPDATE album_id SET updated = 0'); //mysql_query('TRUNCATE album_id'); $query = mysql_query('SELECT MAX(CAST(genre_id AS UNSIGNED)) AS last_genre_id FROM genre'); $rsGenre = mysql_fetch_assoc($query); if ($rsGenre['last_genre_id'] > 0) { $lastGenre_id = $rsGenre['last_genre_id'] + 1; } else { $lastGenre_id = 1; } $cfg['timer'] = 0; // force update //recursiveScanCount_add2table($cfg['media_dir']); recursiveScanCount($cfg['media_dir']); /* $result = mysql_query("update update_progress set update_status = 0, update_time = '" . $updateTime . "', last_update = '" . date('Y-m-d, H:i:s') . "' "); exit(); */ recursiveScan($cfg['media_dir']); //exit(); mysql_query('UPDATE update_progress SET structure_image = "<div class=\'out\'><div class=\'in\' style=\'width: 200px\'></div></div> 100%"'); sleep(1); mysql_query('DELETE FROM album WHERE NOT updated'); mysql_query('DELETE FROM track WHERE NOT updated'); mysql_query('DELETE FROM bitmap WHERE NOT updated'); mysql_query('DELETE FROM genre WHERE NOT updated'); mysql_query('UPDATE server SET value = "' . mysql_real_escape_string($cfg['new_escape_char_hash']) . '" WHERE name = "escape_char_hash" LIMIT 1'); $no_image = mysql_num_rows(mysql_query('SELECT album_id FROM bitmap WHERE flag = 0')); /* if ($no_image > 0) { mysql_query('update update_progress set structure_image = "<a href=\'update.php?action=imageUpdate&flag=0\'><img src=\'' . $cfg['img'] . 'small_image.png\' alt=\'\' class=\'small space\'>Update ' . $no_image . (($no_image == 1) ? ' image' : ' images') . ' from internet</a>"'); } */ if ($no_image > 0) { mysql_query('update update_progress set structure_image = "<a href=\'statistics.php?action=noImageFront\'>No image for ' . $no_image . ($no_image == 1 ? ' folder' : ' folers') . '</a>"'); } else { mysql_query('update update_progress set structure_image = "<i class=\\"fa fa-check icon-ok \\"></i> "'); } // @ob_flush(); // flush(); mysql_query('update update_progress set file_info = "<i class=\\"fa fa-cog larger icon-selected fa-spin\\"></i>"'); $cfg['timer'] = 0; // force update fileInfo(); mysql_query('UPDATE update_progress SET file_info = "<div class=\'out\'><div class=\'in\' style=\'width: 200px\'></div></div> 100%"'); sleep(1); $error = mysql_num_rows(mysql_query('SELECT error FROM track WHERE error != ""')); if ($error > 0) { mysql_query('update update_progress set file_info = "<a href=\'statistics.php?action=fileError\'><i class=\\"fa fa-minus-circle icon-nok\\"></i> ' . $error . ($error == 1 ? ' error' : ' errors') . '</a>"'); } else { mysql_query('update update_progress set file_info = "<i class=\\"fa fa-check icon-ok\\"></i> "'); } // @ob_flush(); // flush(); mysql_query('update update_progress set cleanup = "<i class=\\"fa fa-cog larger icon-selected fa-spin\\"></i> "'); databaseCleanup(); // @ob_flush(); // flush(); mysql_query('update update_progress set cleanup = "<i class=\\"fa fa-check icon-ok\\"></i> "'); $stopTime = new DateTime(); $updateTime = $stopTime->diff($startTime); $updateTime = $updateTime->h . 'h ' . $updateTime->i . 'm ' . $updateTime->s . 's'; $result = mysql_query("update update_progress set \n\t\t\tupdate_status = 0,\n\t\t\tupdate_time = '" . $updateTime . "',\n\t\t\tlast_update = '" . date('Y-m-d, H:i:s') . "'\n\t\t\t"); } else { $structure_image = $row["structure_image"]; echo '<script type="text/javascript"> document.getElementById(\'structure\').innerHTML=" ' . $structure_image . '";</script>' . "\n"; $file_info = $row["file_info"]; echo '<script type="text/javascript"> document.getElementById(\'fileinfo\').innerHTML=" ' . $file_info . '";</script>' . "\n"; $cleanup = $row["cleanup"]; echo '<script type="text/javascript"> document.getElementById(\'cleanup\').innerHTML=" ' . $cleanup . '";</script>' . "\n"; $update_time = $row["update_time"]; echo '<script type="text/javascript"> document.getElementById(\'updateTime\').innerHTML=" ' . $update_time . '";</script>' . "\n"; } $cfg['footer'] = 'close'; require 'include/footer.inc.php'; }