aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrvelices <rv-github@modusoptimus.com>2006-04-18 23:45:21 +0000
committerrvelices <rv-github@modusoptimus.com>2006-04-18 23:45:21 +0000
commit1ff16a6cf126d74c3de2ec9796d45428224c0647 (patch)
treebe123d19ab4305c81f99d44006415f73b610c101
parent4c4faad39c987ff3bb7e691b7e7e910cd9058f94 (diff)
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/branches/branch-1_6@1203 68402e56-0260-453c-a942-63ccdbb3a9ee
Diffstat (limited to '')
-rw-r--r--admin/site_reader_local.php90
-rw-r--r--admin/site_reader_remote.php32
-rw-r--r--admin/site_update.php122
-rw-r--r--language/en_UK.iso-8859-1/admin.lang.php1
-rw-r--r--language/fr_FR.iso-8859-1/admin.lang.php1
-rw-r--r--template/yoga/admin/site_update.tpl7
6 files changed, 174 insertions, 79 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.= ' + ...';
diff --git a/language/en_UK.iso-8859-1/admin.lang.php b/language/en_UK.iso-8859-1/admin.lang.php
index ee934ac40..5464ab83c 100644
--- a/language/en_UK.iso-8859-1/admin.lang.php
+++ b/language/en_UK.iso-8859-1/admin.lang.php
@@ -437,6 +437,7 @@ $lang['update_nb_elements_metadata_sync'] = 'elements informations synchronized
$lang['update_nb_errors'] = 'errors during synchronization';
$lang['update_nb_new_categories'] = 'categories added in the database';
$lang['update_nb_new_elements'] = 'elements added in the database';
+$lang['update_nb_upd_elements'] = 'elements updated in the database';
$lang['update_part_research'] = 'Search for new images in the directories';
$lang['update_research_added'] = 'added';
$lang['update_research_deleted'] = 'deleted';
diff --git a/language/fr_FR.iso-8859-1/admin.lang.php b/language/fr_FR.iso-8859-1/admin.lang.php
index 6dff5ba9d..6cc3b2c77 100644
--- a/language/fr_FR.iso-8859-1/admin.lang.php
+++ b/language/fr_FR.iso-8859-1/admin.lang.php
@@ -440,6 +440,7 @@ $lang['update_nb_elements_metadata_sync'] = 'informations des images synchronisé
$lang['update_nb_errors'] = 'erreurs survenues durant la synchronisation';
$lang['update_nb_new_categories'] = 'catégories ajoutées dans la base de données';
$lang['update_nb_new_elements'] = 'éléments ajoutés dans la base de données';
+$lang['update_nb_upd_elements'] = 'éléments mis à jour dans la base de données';
$lang['update_part_research'] = 'Chercher les nouvelles images dans les répertoires';
$lang['update_research_added'] = 'ajouté';
$lang['update_research_deleted'] = 'supprimé';
diff --git a/template/yoga/admin/site_update.tpl b/template/yoga/admin/site_update.tpl
index 7aa60212b..2ef8ee8e7 100644
--- a/template/yoga/admin/site_update.tpl
+++ b/template/yoga/admin/site_update.tpl
@@ -14,6 +14,7 @@
<li class="update_summary_new">{update_result.NB_NEW_ELEMENTS} {lang:update_nb_new_elements}</li>
<li class="update_summary_del">{update_result.NB_DEL_CATEGORIES} {lang:update_nb_del_categories}</li>
<li class="update_summary_del">{update_result.NB_DEL_ELEMENTS} {lang:update_nb_del_elements}</li>
+ <li>{update_result.NB_UPD_ELEMENTS} {lang:update_nb_upd_elements}</li>
<li class="update_summary_err">{update_result.NB_ERRORS} {lang:update_nb_errors}</li>
</ul>
<!-- END update_result -->
@@ -82,18 +83,18 @@
<legend></legend>
<ul><li><label><input type="checkbox" name="simulate" value="1" checked="checked" {TAG_INPUT_ENABLED} /> {lang:update_simulate}</label></li></ul>
</fieldset>
-
+
<fieldset>
<legend>{lang:update_cats_subset}</legend>
<ul>
- <li>
+ <li>
<select style="width:500px" name="cat" size="10">
<!-- BEGIN category_option -->
<option {introduction.category_option.SELECTED} value="{introduction.category_option.VALUE}">{introduction.category_option.OPTION}</option>
<!-- END category_option -->
</select>
</li>
-
+
<li><label><input type="checkbox" name="subcats-included" value="1" {SUBCATS_INCLUDED_CHECKED} /> {lang:search_subcats_included}</label></li>
</ul>
</fieldset>