diff options
author | plegall <plg@piwigo.org> | 2004-11-30 20:26:44 +0000 |
---|---|---|
committer | plegall <plg@piwigo.org> | 2004-11-30 20:26:44 +0000 |
commit | 759b1e883999c12f7f59865e4fd8c5aea7e90885 (patch) | |
tree | b8e7e52a65c5277f2cb4cd7890d77ae468e9b633 /admin/include/functions_metadata.php | |
parent | 514bac91c66f6eaff63380ec544fe5bccfdebed4 (diff) |
- update_global_rank new function : far more intelligent update. Take into
account the possiblity to have category tree not in category id ascending
order
- update global_rank when moving categories among the same parent
- new function mass_updates : depending on MySQL version, create a temporary
table, make one big insert and one big update by joining 2 tables (4.0.4
or above) or make 1 update per primary key
- function update_category improved for representative_picture_id check :
only one useful query (equivalent to NOT EXISTS) instead of N (N = number
of categories) queries
git-svn-id: http://piwigo.org/svn/trunk@625 68402e56-0260-453c-a942-63ccdbb3a9ee
Diffstat (limited to '')
-rw-r--r-- | admin/include/functions_metadata.php | 149 |
1 files changed, 17 insertions, 132 deletions
diff --git a/admin/include/functions_metadata.php b/admin/include/functions_metadata.php index 2e66606d2..023ab219e 100644 --- a/admin/include/functions_metadata.php +++ b/admin/include/functions_metadata.php @@ -68,18 +68,18 @@ function update_metadata($files) define('CURRENT_DATE', date('Y-m-d')); } - $inserts = array(); + $datas = array(); foreach ($files as $id => $file) { - $insert = array(); - $insert['id'] = $id; - $insert['filesize'] = floor(filesize($file)/1024); + $data = array(); + $data['id'] = $id; + $data['filesize'] = floor(filesize($file)/1024); if ($image_size = @getimagesize($file)) { - $insert['width'] = $image_size[0]; - $insert['height'] = $image_size[1]; + $data['width'] = $image_size[0]; + $data['height'] = $image_size[1]; } if ($conf['use_exif']) @@ -88,11 +88,8 @@ function update_metadata($files) { if (isset($exif['DateTime'])) { - preg_match('/^(\d{4}).(\d{2}).(\d{2})/' - ,$exif['DateTime'] - ,$matches); - $insert['date_creation'] = - "'".$matches[1].'-'.$matches[2].'-'.$matches[3]."'"; + preg_match('/^(\d{4}).(\d{2}).(\d{2})/',$exif['DateTime'],$matches); + $data['date_creation'] = $matches[1].'-'.$matches[2].'-'.$matches[3]; } } } @@ -104,135 +101,23 @@ function update_metadata($files) { foreach (array_keys($iptc) as $key) { - $insert[$key] = "'".addslashes($iptc[$key])."'"; + $data[$key] = "'".addslashes($iptc[$key])."'"; } } } - $insert['date_metadata_update'] = "'".CURRENT_DATE."'"; + $data['date_metadata_update'] = CURRENT_DATE; - array_push($inserts, $insert); + array_push($datas, $data); } - if (count($inserts) > 0) + if (count($datas) > 0) { - $dbfields = array( - 'id','filesize','width','height','name','author','comment' - ,'date_creation','keywords','date_metadata_update' - ); - - // depending on the MySQL version, we use the multi table update or N - // update queries - $query = 'SELECT VERSION() AS version;'; - $row = mysql_fetch_array(pwg_query($query)); - if (version_compare($row['version'],'4.0.4') < 0) - { - // MySQL is prior to version 4.0.4, multi table update feature is not - // available - echo 'MySQL is prior to version 4.0.4, multi table update feature is not available<br />'; - foreach ($inserts as $insert) - { - $query = ' -UPDATE '.IMAGES_TABLE.' - SET '; - foreach (array_diff(array_keys($insert),array('id')) as $num => $key) - { - if ($num > 1) - { - $query.= ', '; - } - $query.= $key.' = '.$insert[$key]; - } - $query.= ' - WHERE id = '.$insert['id'].' -;'; - // echo '<pre>'.$query.'</pre>'; - pwg_query($query); - } - } - else - { - // creation of the temporary table - $query = ' -DESCRIBE '.IMAGES_TABLE.' -;'; - $result = pwg_query($query); - $columns = array(); - while ($row = mysql_fetch_array($result)) - { - if (in_array($row['Field'], $dbfields)) - { - $column = $row['Field']; - $column.= ' '.$row['Type']; - if (!isset($row['Null']) or $row['Null'] == '') - { - $column.= ' NOT NULL'; - } - if (isset($row['Default'])) - { - $column.= " default '".$row['Default']."'"; - } - array_push($columns, $column); - } - } - $query = ' -CREATE TEMPORARY TABLE '.IMAGE_METADATA_TABLE.' -( -'.implode(",\n", $columns).', -PRIMARY KEY (id) -) -;'; - // echo '<pre>'.$query.'</pre>'; - pwg_query($query); - // inserts all found pictures - $query = ' -INSERT INTO '.IMAGE_METADATA_TABLE.' - ('.implode(',', $dbfields).') - VALUES - '; - foreach ($inserts as $insert_id => $insert) - { - $query.= ' -'; - if ($insert_id > 0) - { - $query.= ','; - } - $query.= '('; - foreach ($dbfields as $field_id => $dbfield) - { - if ($field_id > 0) - { - $query.= ','; - } - - if (!isset($insert[$dbfield]) or $insert[$dbfield] == '') - { - $query.= 'NULL'; - } - else - { - $query.= $insert[$dbfield]; - } - } - $query.=')'; - } - $query.= ' -;'; - // echo '<pre>'.$query.'</pre>'; - pwg_query($query); - // update of images table by joining with temporary table - $query = ' -UPDATE '.IMAGES_TABLE.' AS images, '.IMAGE_METADATA_TABLE.' as metadata - SET '.implode("\n , ", - array_map( - create_function('$s', 'return "images.$s = metadata.$s";') - , array_diff($dbfields, array('id')))).' - WHERE images.id = metadata.id -;'; - echo '<pre>'.$query.'</pre>'; - pwg_query($query); - } + $fields = array('primary' => array('id'), + 'update' => array('filesize','width','height','name', + 'author','comment','date_creation', + 'keywords','date_metadata_update')); + mass_updates(IMAGES_TABLE, $fields, $datas); } } |