From: garvinhicking
Date: Fri, 10 Feb 2006 13:43:43 +0000 (+0000)
Subject: Commit on-the-fly image synchronization by Marty.
X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=9293c95352de6df6ef1378b45e720ce238a2eabb;p=s9y.git
Commit on-the-fly image synchronization by Marty.
Currently in debugging state.
---
diff --git a/docs/NEWS b/docs/NEWS
index 2fb8895..b9a3db0 100644
--- a/docs/NEWS
+++ b/docs/NEWS
@@ -3,7 +3,10 @@
Version 1.1-alpha1()
------------------------------------------------------------------------
- * Added first patches for image directory permissions. (garvinhicking)
+ * Added on-the-fly synchronizing of the Serendipity media database
+ with the file system (Marty, garvinhicking)
+
+ * Introduce permission setup for media directories (garvinhicking)
* Added config option for specifying number of entries in the RSS
feed (garvinhicking)
diff --git a/include/functions.inc.php b/include/functions.inc.php
index 7d58a37..80c4366 100644
--- a/include/functions.inc.php
+++ b/include/functions.inc.php
@@ -967,5 +967,18 @@ function serendipity_updateCategory($cid, $name, $desc, $authorid, $icon, $paren
}
+if (!function_exists('microtime_float')) {
+ /**
+ * Get current timestamp as microseconds
+ *
+ * @access public
+ * @return float the time
+ */
+ function microtime_float() {
+ list($usec, $sec) = explode(" ", microtime());
+ return ((float)$usec + (float)$sec);
+ }
+}
+
define("serendipity_FUNCTIONS_LOADED", true);
/* vim: set sts=4 ts=4 expandtab : */
diff --git a/include/functions_images.inc.php b/include/functions_images.inc.php
index a5e6b51..18565b9 100644
--- a/include/functions_images.inc.php
+++ b/include/functions_images.inc.php
@@ -231,7 +231,13 @@ function serendipity_fetchImages($group = false, $start = 0, $end = 20, $images
$basedir = $serendipity['serendipityPath'] . $serendipity['uploadPath'];
$images = array();
if ($dir = @opendir($basedir . $odir)) {
- while(false !== ($f = readdir($dir))) {
+ $aTempArray = array();
+ while (($file = @readdir($dir)) !== false) {
+ array_push($aTempArray, $file);
+ }
+ @closedir($dir);
+ sort($aTempArray);
+ foreach($aTempArray as $f) {
if ($f != '.' && $f != '..' && strpos($f, $serendipity['thumbSuffix']) === false) {
$cdir = ($odir != '' ? $odir . '/' : '');
if (is_dir($basedir . $odir . '/' . $f)) {
@@ -345,7 +351,7 @@ function serendipity_insertHotlinkedImageInDatabase($filename, $url, $authorid =
function serendipity_insertImageInDatabase($filename, $directory, $authorid = 0, $time = NULL) {
global $serendipity;
- if ( is_null($time) ) {
+ if (is_null($time)) {
$time = time();
}
@@ -1139,6 +1145,128 @@ function serendipity_displayImageList($page = 0, $lineBreak = NULL, $manage = fa
$perPage = (!empty($serendipity['GET']['sortorder']['perpage']) ? $serendipity['GET']['sortorder']['perpage'] : $sort_row_interval[0]);
$start = ($page-1) * $perPage;
+ ## SYNCH START ##
+ $aExclude = array("CVS" => true, ".svn" => true);
+ serendipity_plugin_api::hook_event('backend_media_path_exclude_directories', $aExclude);
+ $paths = array();
+ $aFilesOnDisk = array();
+
+ $aResultSet = serendipity_traversePath(
+ $serendipity['serendipityPath'] . $serendipity['uploadPath']. $limit_path,
+ '',
+ false,
+ NULL,
+ 1,
+ NULL,
+ FALSE,
+ $aExclude
+ );
+
+ foreach ($aResultSet AS $sKey => $sFile) {
+ if ($sFile['directory']) {
+ echo "{$sFile['relpath']} is a directory. "; #DEBUG
+ array_push($paths, $sFile);
+ } else {
+ echo "{$sFile['relpath']} is a file. "; #DEBUG
+ // Store the file in our array, remove any ending slashes
+ $aFilesOnDisk[$sFile['relpath']] = 1;
+ }
+ unset($aResultSet[$sKey]);
+ }
+ sort($paths);
+ echo "
Got files:
" . print_r($aFilesOnDisk, true) . "
"; #DEBUG
+ $serendipity['current_image_hash'] = md5(serialize($aFilesOnDisk));
+ $serendipity['current_image_hash'] = md5(time()); #DEBUGGING
+
+ $nTimeStart = microtime_float();
+ // MTG 21/01/06: request all images from the database, delete any which don't exist
+ // on the filesystem, and mark off files from the file list which are already
+ // in the database
+
+ $nCount = 0;
+ if (serendipity_checkPermission('adminImagesSync') && $serendipity['current_image_hash'] != $serendipity['last_image_hash']) {
+ $aResultSet = serendipity_db_query("SELECT path, name, extension, thumbnail_name, id
+ FROM {$serendipity['dbPrefix']}images", false, 'assoc');
+ echo "