aboutsummaryrefslogtreecommitdiffstats
path: root/admin
diff options
context:
space:
mode:
authorrvelices <rv-github@modusoptimus.com>2006-04-18 23:46:53 +0000
committerrvelices <rv-github@modusoptimus.com>2006-04-18 23:46:53 +0000
commit94c39903dcc29879c8827dfd398af9434c1dc95e (patch)
tree879c782b797ac0451fb99e61dc5c8ce64858474e /admin
parent8e4c71c4bdac0d4914c7b631b1ff34b90fcb9211 (diff)
merge r1203 from branch-1_6 into trunk
bug 335: tn_ext, has_high and representative_ext are updated during file synchronization and not metadata synchronization git-svn-id: http://piwigo.org/svn/trunk@1204 68402e56-0260-453c-a942-63ccdbb3a9ee
Diffstat (limited to 'admin')
-rw-r--r--admin/site_reader_local.php90
-rw-r--r--admin/site_reader_remote.php32
-rw-r--r--admin/site_update.php122
3 files changed, 168 insertions, 76 deletions
diff --git a/admin/site_reader_local.php b/admin/site_reader_local.php
index 23161d2e2..0f4693883 100644
--- a/admin/site_reader_local.php
+++ b/admin/site_reader_local.php
@@ -44,7 +44,7 @@ function LocalSiteReader($url)
function open()
{
global $errors;
-
+
if (!is_dir($this->site_url))
{
array_push(
@@ -54,10 +54,10 @@ function open()
'type' => 'PWG-ERROR-NO-FS'
)
);
-
+
return false;
}
-
+
return true;
}
@@ -77,10 +77,6 @@ function get_full_directories($basedir)
function get_elements($path)
{
global $conf;
- if (!isset($conf['flip_picture_ext']))
- {
- $conf['flip_picture_ext'] = array_flip($conf['picture_ext']);
- }
if (!isset($conf['flip_file_ext']))
{
$conf['flip_file_ext'] = array_flip($conf['file_ext']);
@@ -97,26 +93,13 @@ function get_elements($path)
$extension = get_extension($node);
$filename_wo_ext = get_filename_wo_extension($node);
- // searching the thumbnail
- $tn_ext = $this->get_tn_ext($path, $filename_wo_ext);
-
- if (isset($conf['flip_picture_ext'][$extension]))
+ if ( isset($conf['flip_file_ext'][$extension]) )
{
+ $tn_ext = $this->get_tn_ext($path, $filename_wo_ext);
$fs[ $path.'/'.$node ] = array(
'tn_ext' => $tn_ext,
- 'has_high' => $this->get_has_high($path, $node)
- );
- }
- else if (isset($conf['flip_file_ext'][$extension]))
- { // file not a picture
- $representative_ext = $this->get_representative_ext($path, $filename_wo_ext);
-
- $fs[ $path.'/'.$node ] = array(
- 'tn_ext' => $tn_ext,
- 'representative_ext' => $representative_ext
);
}
-
}
elseif (is_dir($path.'/'.$node)
and $node != '.'
@@ -140,15 +123,42 @@ function get_elements($path)
}
// returns the name of the attributes that are supported for
-// update/synchronization according to configuration
+// files update/synchronization
function get_update_attributes()
{
+ return array('tn_ext', 'has_high', 'representative_ext');
+}
+
+function get_element_update_attributes($file)
+{
+ global $conf;
+ $data = array();
+
+ $filename = basename($file);
+ $dirname = dirname($file);
+ $filename_wo_ext = get_filename_wo_extension($filename);
+ $extension = get_extension($filename);
+
+ $data['tn_ext'] = $this->get_tn_ext($dirname, $filename_wo_ext);
+ $data['has_high'] = $this->get_has_high($dirname, $filename);
+
+ if ( !isset($conf['flip_picture_ext'][$extension]) )
+ {
+ $data['representative_ext'] = $this->get_representative_ext(
+ $dirname, $filename_wo_ext
+ );
+ }
+ return $data;
+}
+
+// returns the name of the attributes that are supported for
+// metadata update/synchronization according to configuration
+function get_metadata_attributes()
+{
global $conf;
-
- $update_fields = array(
- 'has_high', 'representative_ext', 'filesize', 'width', 'height'
- );
-
+
+ $update_fields = array('filesize', 'width', 'height');
+
if ($conf['use_exif'])
{
$update_fields =
@@ -166,12 +176,12 @@ function get_update_attributes()
array_keys($conf['use_iptc_mapping'])
);
}
-
+
return $update_fields;
}
// returns a hash of attributes (metadata+filesize+width,...) for file
-function get_element_update_attributes($file)
+function get_element_metadata($file)
{
global $conf;
if (!is_file($file))
@@ -181,16 +191,8 @@ function get_element_update_attributes($file)
$data = array();
- $filename = basename($file);
-
- $data['has_high'] = $this->get_has_high(dirname($file), $filename);
-
- $data['representative_ext'] = $this->get_representative_ext(
- dirname($file),
- get_filename_wo_extension($filename)
- );
-
$data['filesize'] = floor(filesize($file)/1024);
+
if ($image_size = @getimagesize($file))
{
$data['width'] = $image_size[0];
@@ -221,7 +223,7 @@ function get_element_update_attributes($file)
}
}
}
-
+
return $data;
}
@@ -245,10 +247,10 @@ function get_representative_ext($path, $filename_wo_ext)
function get_tn_ext($path, $filename_wo_ext)
{
global $conf;
-
+
$base_test =
$path.'/thumbnail/'.$conf['prefix_thumbnail'].$filename_wo_ext.'.';
-
+
foreach ($conf['picture_ext'] as $ext)
{
$test = $base_test.$ext;
@@ -257,7 +259,7 @@ function get_tn_ext($path, $filename_wo_ext)
return $ext;
}
}
-
+
return null;
}
@@ -267,7 +269,7 @@ function get_has_high($path, $filename)
{
return 'true';
}
-
+
return null;
}
diff --git a/admin/site_reader_remote.php b/admin/site_reader_remote.php
index 03ad7d45a..dd0038877 100644
--- a/admin/site_reader_remote.php
+++ b/admin/site_reader_remote.php
@@ -35,16 +35,19 @@ var $listing_url;
var $site_dirs;
var $site_files;
var $insert_attributes;
-var $update_attributes;
+var $metadata_attributes;
function RemoteSiteReader($url, $listing_url)
{
$this->site_url = $url;
$this->insert_attributes = array(
- 'tn_ext', 'representative_ext', 'has_high'
+ 'tn_ext',
);
$this->update_attributes = array(
- 'representative_ext', 'has_high', 'filesize', 'width', 'height'
+ 'tn_ext', 'representative_ext', 'has_high',
+ );
+ $this->metadata_attributes = array(
+ 'filesize', 'width', 'height'
);
if (!isset($listing_url))
@@ -85,8 +88,8 @@ function open()
return false;
}
- $this->update_attributes = array_merge(
- $this->update_attributes,
+ $this->metadata_attributes = array_merge(
+ $this->metadata_attributes,
explode(',', getAttribute($info_xml_element, 'metadata'))
);
@@ -154,13 +157,12 @@ function get_elements($path)
}
// returns the name of the attributes that are supported for
-// update/synchronization according to listing.xml
+// files update/synchronization
function get_update_attributes()
{
return $this->update_attributes;
}
-// returns a hash of attributes (metadata+filesize+width,...) for file
function get_element_update_attributes($file)
{
return $this->get_element_attributes(
@@ -169,6 +171,22 @@ function get_element_update_attributes($file)
);
}
+// returns the name of the attributes that are supported for
+// metadata update/synchronization according to listing.xml
+function get_metadata_attributes()
+{
+ return $this->metadata_attributes;
+}
+
+// returns a hash of attributes (metadata+width,...) for file
+function get_element_metadata($file)
+{
+ return $this->get_element_attributes(
+ $file,
+ $this->metadata_attributes
+ );
+}
+
//-------------------------------------------------- private functions --------
/**
* Returns a hash of image/file attributes
diff --git a/admin/site_update.php b/admin/site_update.php
index d6129826b..40615f073 100644
--- a/admin/site_update.php
+++ b/admin/site_update.php
@@ -103,6 +103,10 @@ else
$general_failure = true;
if (isset($_POST['submit']))
{
+ if (!isset($conf['flip_picture_ext']))
+ {
+ $conf['flip_picture_ext'] = array_flip($conf['picture_ext']);
+ }
if ($site_reader->open())
{
$general_failure = false;
@@ -129,6 +133,7 @@ if (isset($_POST['submit'])
$counts['del_categories'] = 0;
$counts['del_elements'] = 0;
$counts['new_elements'] = 0;
+ $counts['upd_elements'] = 0;
$start = get_moment();
// which categories to update ?
@@ -441,7 +446,7 @@ SELECT IF(MAX(id)+1 IS NULL, 1, MAX(id)+1) AS next_element_id
// 2 cases : the element is a picture or not. Indeed, for a picture
// thumbnail is mandatory and for non picture element, thumbnail and
// representative are optionnal
- if (in_array(get_extension($filename), $conf['picture_ext']))
+ if ( isset( $conf['flip_picture_ext'][get_extension($filename)] ) )
{
// if we found a thumnbnail corresponding to our picture...
if (isset($fs[$path]['tn_ext']))
@@ -451,9 +456,6 @@ SELECT IF(MAX(id)+1 IS NULL, 1, MAX(id)+1) AS next_element_id
'file' => $filename,
'date_available' => CURRENT_DATE,
'tn_ext' => $fs[$path]['tn_ext'],
- 'has_high' => isset($fs[$path]['has_high'])
- ? $fs[$path]['has_high']
- : null,
'path' => $path,
'storage_category_id' => $db_fulldirs[$dirname],
);
@@ -496,15 +498,9 @@ SELECT IF(MAX(id)+1 IS NULL, 1, MAX(id)+1) AS next_element_id
'file' => $filename,
'date_available' => CURRENT_DATE,
'path' => $path,
- 'has_high' => isset($fs[$path]['has_high'])
- ? $fs[$path]['has_high']
- : null,
'tn_ext' => isset($fs[$path]['tn_ext'])
? $fs[$path]['tn_ext']
: null,
- 'representative_ext' => isset($fs[$path]['representative_ext'])
- ? $fs[$path]['representative_ext']
- : null,
'storage_category_id' => $db_fulldirs[$dirname],
);
@@ -634,18 +630,9 @@ DELETE
// | synchronize files |
// +-----------------------------------------------------------------------+
if (isset($_POST['submit'])
- and ($_POST['sync'] == 'dirs' or $_POST['sync'] == 'files'))
+ and ($_POST['sync'] == 'dirs' or $_POST['sync'] == 'files')
+ and !$general_failure )
{
- $template->assign_block_vars(
- 'update_result',
- array(
- 'NB_NEW_CATEGORIES'=>$counts['new_categories'],
- 'NB_DEL_CATEGORIES'=>$counts['del_categories'],
- 'NB_NEW_ELEMENTS'=>$counts['new_elements'],
- 'NB_DEL_ELEMENTS'=>$counts['del_elements'],
- 'NB_ERRORS'=>count($errors),
- ));
-
if (!$simulate)
{
$start = get_moment();
@@ -660,6 +647,91 @@ if (isset($_POST['submit'])
echo get_elapsed_time($start, get_moment());
echo ' -->'."\n";
}
+
+ if ($_POST['sync'] == 'files')
+ {
+ $start = get_moment();
+ $opts['category_id'] = '';
+ $opts['recursive'] = true;
+ if (isset($_POST['cat']))
+ {
+ $opts['category_id'] = $_POST['cat'];
+ if (!isset($_POST['subcats-included']) or $_POST['subcats-included'] != 1)
+ {
+ $opts['recursive'] = false;
+ }
+ }
+ $files = get_filelist($opts['category_id'], $site_id,
+ $opts['recursive'],
+ false);
+ echo '<!-- get_filelist : ';
+ echo get_elapsed_time($start, get_moment());
+ echo ' -->'."\n";
+ $start = get_moment();
+
+ $datas = array();
+ foreach ( $files as $id=>$file )
+ {
+ $data = $site_reader->get_element_update_attributes($file);
+ if ( !is_array($data) )
+ {
+ continue;
+ }
+ $extension = get_extension($file);
+ if ( isset($conf['flip_picture_ext'][$extension]) )
+ {
+ if ( !isset($data['tn_ext']) )
+ {
+ array_push(
+ $errors,
+ array(
+ 'path' => $file,
+ 'type' => 'PWG-UPDATE-2'
+ )
+ );
+ continue;
+ }
+ }
+
+ $data['id']=$id;
+ array_push($datas, $data);
+ } // end foreach file
+
+ $counts['upd_elements'] = count($datas);
+ if (!$simulate and count($datas)>0 )
+ {
+ mass_updates(
+ IMAGES_TABLE,
+ // fields
+ array(
+ 'primary' => array('id'),
+ 'update' => $site_reader->get_update_attributes(),
+ ),
+ $datas
+ );
+ }
+ echo '<!-- update files : ';
+ echo get_elapsed_time($start,get_moment());
+ echo ' -->'."\n";
+ }// end if sync files
+}
+
+// +-----------------------------------------------------------------------+
+// | synchronize files |
+// +-----------------------------------------------------------------------+
+if (isset($_POST['submit'])
+ and ($_POST['sync'] == 'dirs' or $_POST['sync'] == 'files'))
+{
+ $template->assign_block_vars(
+ 'update_result',
+ array(
+ 'NB_NEW_CATEGORIES'=>$counts['new_categories'],
+ 'NB_DEL_CATEGORIES'=>$counts['del_categories'],
+ 'NB_NEW_ELEMENTS'=>$counts['new_elements'],
+ 'NB_DEL_ELEMENTS'=>$counts['del_elements'],
+ 'NB_UPD_ELEMENTS'=>$counts['upd_elements'],
+ 'NB_ERRORS'=>count($errors),
+ ));
}
// +-----------------------------------------------------------------------+
@@ -703,7 +775,7 @@ if (isset($_POST['submit']) and preg_match('/^metadata/', $_POST['sync'])
$tags_of = array();
foreach ( $files as $id=>$file )
{
- $data = $site_reader->get_element_update_attributes($file);
+ $data = $site_reader->get_element_metadata($file);
if ( is_array($data) )
{
$data['date_metadata_update'] = CURRENT_DATE;
@@ -718,7 +790,7 @@ if (isset($_POST['submit']) and preg_match('/^metadata/', $_POST['sync'])
{
$tags_of[$id] = array();
}
-
+
foreach (explode(',', $data[$key]) as $tag_name)
{
array_push(
@@ -747,7 +819,7 @@ if (isset($_POST['submit']) and preg_match('/^metadata/', $_POST['sync'])
'update' => array_unique(
array_merge(
array_diff(
- $site_reader->get_update_attributes(),
+ $site_reader->get_metadata_attributes(),
// keywords and tags fields are managed separately
array('keywords', 'tags')
),
@@ -785,7 +857,7 @@ if (isset($simulate) and $simulate)
// used_metadata string is displayed to inform admin which metadata will be
// used from files for synchronization
-$used_metadata = implode( ', ', $site_reader->get_update_attributes());
+$used_metadata = implode( ', ', $site_reader->get_metadata_attributes());
if ($site_is_remote and !isset($_POST['submit']) )
{
$used_metadata.= ' + ...';