[Linpha-cvs] SF.net SVN: linpha: [4630] trunk/linpha2
Status: Inactive
Brought to you by:
bzrudi
From: <fan...@us...> - 2006-11-10 06:41:01
|
Revision: 4630 http://svn.sourceforge.net/linpha/?rev=4630&view=rev Author: fangehrn Date: 2006-11-09 14:22:06 -0800 (Thu, 09 Nov 2006) Log Message: ----------- 2006-11-09 flo * added a maintenance part in the admin pages * added a db maintenance script - currently only detections implemented Modified Paths: -------------- trunk/linpha2/ChangeLog trunk/linpha2/admin/index.php trunk/linpha2/docs/dev/TODO.txt trunk/linpha2/lib/classes/linpha.filesys.class.php trunk/linpha2/lib/classes/linpha.functions.php trunk/linpha2/lib/classes/linpha.image.class.php trunk/linpha2/lib/classes/linpha.imgview.class.php trunk/linpha2/lib/classes/linpha.sql.class.php Added Paths: ----------- trunk/linpha2/admin/maintenance.php trunk/linpha2/admin/maintenance_db.php trunk/linpha2/admin/maintenance_import.php Removed Paths: ------------- trunk/linpha2/admin/import.php Modified: trunk/linpha2/ChangeLog =================================================================== --- trunk/linpha2/ChangeLog 2006-11-09 16:05:39 UTC (rev 4629) +++ trunk/linpha2/ChangeLog 2006-11-09 22:22:06 UTC (rev 4630) @@ -1,3 +1,8 @@ +2006-11-09 flo + * added a maintenance part in the admin pages + * added a db maintenance script + - currently only detections implemented + 2006-11-08 flo * finished new folder thumbnail - use a gif instead of png Deleted: trunk/linpha2/admin/import.php =================================================================== --- trunk/linpha2/admin/import.php 2006-11-09 16:05:39 UTC (rev 4629) +++ trunk/linpha2/admin/import.php 2006-11-09 22:22:06 UTC (rev 4630) @@ -1,426 +0,0 @@ -<?php -/* -* Copyright (c) 2005 Heiko Rutenbeck <bz...@tu...> -* Florian Angehrn -* -* This program is free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation; either version 2 of the License, or -* (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program; if not, write to the Free Software -* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -*/ - -/** - * This file updates the database - * @package Import - */ - -if(!defined('LINPHA_DIR')) { exit(1); } - -/** - * try it, it works sometimes - */ -ini_set("max_execution_time", "6000"); - - -$array_meta = Array('exif','iptc','xmp'); - -if( isset($_POST['cmd']) && $_POST['cmd']=='import') -{ - echo '<h1 class="linStyle">'.i18n("Running Import...").'</h1>'; - - if(!isset($_REQUEST['album_select']) OR $_REQUEST['album_select'][0]=='all') - { - $all_albums = true; - } - else - { - $all_albums = false; - } - - - /** - * import - */ - if($_REQUEST['index_import']=='index') - { - echo '<h2 class="linStyle">'.i18n("Directory Import").'</h2>'; - if($all_albums) - { - echo i18n("Parsing All Directories...").'<br />'; - LinImport::updateDir( $parent_id = 0, $recursive = true, $dryrun = false ); - } - else - { - foreach($_REQUEST['album_select'] AS $key=>$value) - { - $data = $GLOBALS['linpha']->db->GetRow("SELECT name FROM ".PREFIX."photos WHERE id = '".LinSql::linAddslashes($value)."'"); - echo i18n("Parsing Directory:").' '.$data['name'].'<br />'; - LinImport::updateDir( $parent_id = $value, $recursive = true, $dryrun = false ); - } - } - - if( isset($GLOBALS['linpha']->template->output['sys_log']) ) - { - echo $GLOBALS['linpha']->template->output['sys_log']; - unset($GLOBALS['linpha']->template->output['sys_log']); - } - - echo '<br />'; - } - - /** - * thumbnails - */ - /** - * @todo should we create the folder thumbnails here? - * they will be automatically created on each visit - * we would have to take care to the script backwards, - * that means first of the depest subfolder until we're on top - */ - if($_REQUEST['index_thumbnails']!='no' OR isset($_REQUEST['index_thumbnails_delete'])) - { - echo '<h2 class="linStyle">'.i18n("Thumbnails").'</h2>'; - - $thumbnail = new LinImage(); - - if($_REQUEST['index_thumbnails']=='recreate') - { - $_GET['force'] = true; - } - - /** - * all albums selected - */ - if($all_albums) - { - /** - * delete thumbnails - */ - if( isset($_REQUEST['index_thumbnails_delete']) ) - { - echo i18n("Delete All Existing Thumbnails...").'<br />'; - $thumbcachepath = LinSql::getPath('cache').'/thumb'; - LinFilesys::rm_rf( $thumbcachepath ); // all subfolders will automatically be recreated on each image access - if(file_exists($thumbcachepath)) - { - echo i18n("Warning while deleting file/folder, check permissions!").'<br />'; - } - else - { - mkdir( $thumbcachepath ); - } - } - - /** - * set query string for create/recreate thumbnails - */ - if($_REQUEST['index_thumbnails']!='no') - { - echo '<h3>'.i18n("Parsing All Directories...").'</h3><br />'; - $createthumbquery = $GLOBALS['linpha']->db->Execute("SELECT id FROM ".PREFIX."photos WHERE img_type <> 0 AND img_type <> 9999999"); - } - } - else // $all_albums == false -> not all directory selected - { - /** - * go through each selected directory - */ - foreach($_REQUEST['album_select'] AS $key=>$value) - { - $data = $GLOBALS['linpha']->db->GetRow("SELECT name FROM ".PREFIX."photos WHERE id = '".LinSql::linAddslashes($value)."'"); - echo i18n("Parsing Directory:").' '.$data['name'].'<br />'; - - $sql = "SELECT id FROM ".PREFIX."photos WHERE " . - "parent_id = '".LinSql::linAddslashes($value)."' AND " . - "img_type <> 0 AND img_type <> 9999999"; - - /** - * delete thumbnails - */ - if( isset($_REQUEST['index_thumbnails_delete']) ) - { - echo i18n("Delete Thumbnails"); - $query = $GLOBALS['linpha']->db->Execute($sql); - while($data = $query->FetchRow(ADODB_FETCH_NUM)) - { - if( LinImage::deleteCachedThumbnail($data[0]) ) - { - echo " ".$data[0].","; - } - } - echo '<br />'; - } - - /** - * set query string for create/recreate thumbnails - */ - if($_REQUEST['index_thumbnails']!='no') - { - $createthumbquery = $GLOBALS['linpha']->db->Execute($sql); - } - } - } - - /** - * now create thumbnails, $query has been set previously - */ - if($_REQUEST['index_thumbnails']!='no') - { - echo i18n("Create Thumbnail"); - while($data = $createthumbquery->FetchRow(ADODB_FETCH_NUM)) - { - if( ! $thumbnail->createThumbnail($data[0]) ) - { - echo i18n("Error While Creating Thumbnail!")."<br />Error: ".$thumbnail->error_msg."<br />"; - } - if( ! $thumbnail->isCached ) // thumbnail wasn't cached -> now created! - { - echo " ".$data[0].","; - } - flush(); - } - echo '<br />'; - } - - echo '<br />'; - } - - - /** - * exif, iptc, xmp - * - * if "Delete First" and "All albums" was selected, the whole table will be deleted - */ - include_once(LINPHA_DIR.'/lib/classes/linpha.metadata.class.php'); - $MetaData = new MetaData(); - - foreach($array_meta AS $meta_value) - { - if( isset( $_REQUEST['index_'.$meta_value] ) && - ( $_REQUEST['index_'.$meta_value] == 'index' OR isset($_REQUEST['index_'.$meta_value.'_delete']) ) ) - { - echo '<h2 class="linStyle">'.i18n("File Indexing").' ('.strtoupper($meta_value).')</h2>'; - - /** - * get imgids to indexing, if reindex is selected: delete these entries first - */ - if($all_albums) - { - echo i18n("All Directories selected").'<br />'; - - $query = $GLOBALS['linpha']->db->Execute("SELECT id, md5sum FROM ".PREFIX."photos WHERE img_type <> 0 AND img_type <> 9999999"); - while($data = $query->FetchRow()) - { - $array_meta_ids[$data['id']] = $data['md5sum']; - } - } - else - { - echo i18n("Directory selected:").' '; - foreach($_REQUEST['album_select'] AS $key=>$value) - { - $data = $GLOBALS['linpha']->db->GetRow("SELECT name FROM ".PREFIX."photos WHERE id = '".LinSql::linAddslashes($value)."'"); - echo $data['name'].', '; - - $query = $GLOBALS['linpha']->db->Execute("SELECT id, md5sum FROM ".PREFIX."photos WHERE " . - "parent_id = '".LinSql::linAddslashes($value)."' AND " . - "img_type <> 0 AND img_type <> 9999999"); - while($data = $query->FetchRow(ADODB_FETCH_NUM)) - { - $array_meta_ids[$data['id']] = $data['md5sum']; - } - } - echo '<br />'; - } - - /** - * delete first (if selected) - */ - if( isset($_REQUEST['index_'.$meta_value.'_delete']) ) - { - if( $all_albums ) - { - echo i18n("Delete all index data").'<br />'; - $GLOBALS['linpha']->db->Execute("DELETE FROM ".PREFIX."meta_".$meta_value); - } - elseif( isset($array_meta_ids) ) - { - echo i18n("Delete index data of selected directories").'<br />'; - foreach($array_meta_ids AS $id=>$md5sum) - { - $GLOBALS['linpha']->db->Execute("DELETE FROM ".PREFIX."meta_".$meta_value." WHERE md5sum = '".$md5sum."'"); - } - } - } - - /** - * index image, parse all saved ids - */ - if( isset($array_meta_ids) && $_REQUEST['index_'.$meta_value] == 'index' ) - { - $MetaData->setFields($meta_value); - - echo i18n("Index Image"); - - foreach($array_meta_ids AS $id=>$md5sum) - { - $query = $GLOBALS['linpha']->db->Execute("SELECT md5sum ". - "FROM ".PREFIX."meta_exif WHERE md5sum = '".$md5sum."'"); - - if( $query->EOF) // not a single value returned - { - $full_filename = LinSql::getFullImagePath($id); - - switch($meta_value) - { - case 'exif': - include_once(LINPHA_DIR.'/lib/classes/phpmeta/JPEG.php'); // used for jpeg comment - include_once(LINPHA_DIR.'/lib/classes/phpmeta/EXIF.php'); - $MetaData->saveExifData( $full_filename,$md5sum ); - break; - case 'iptc': - include_once(LINPHA_DIR.'/lib/classes/phpmeta/Photoshop_IRB.php'); - include_once(LINPHA_DIR.'/lib/classes/phpmeta/JPEG.php'); - $MetaData->saveIptcData( $full_filename,$md5sum ); - break; - case 'xmp': - break; - } - - echo " ".$id.","; - flush(); - } - } - - } - - echo '<br /><br />'; - } - unset($array_meta_ids); - } -} - - -echo '<h1 class="linStyle">'.i18n("Import").'</h1>'; -echo i18n("Select Folders For Import/Update:"); -?> -<br /> -<form action="./?cat=import" method="POST"> -<select name="album_select[]" size="10" multiple="multiple" style="width: 500px;"> -<?php linBuildAlbumSelect($with_all_albs_entry=true); ?> -</select> -<br /><br /> - -<?php echo i18n("Import").':'; ?> -<br /> - -<input type="checkbox" id="index_import_detect_filechanges" name="force_update" value="true" /><label for="index_import_detect_filechanges"> <?php echo i18n("Detect File Changes"); ?></label><br /> -<input type="radio" id="index_import_no" name="index_import" value="no" /><label for="index_import_no"> <?php echo i18n("No Import"); ?></label><br /> -<input type="radio" id="index_import_index" name="index_import" value="index" checked="checked" /><label for="index_import_index"> <?php echo i18n("Import"); ?></label><br /> -<br /> - -<?php echo i18n("Thumbnails").':'; ?> -<br /> -<input type="checkbox" id="index_thumbnails_deletefirst" name="index_thumbnails_delete" value="delete" /><label for="index_thumbnails_deletefirst"> <?php echo i18n("Delete First"); ?></label><br /> -<input type="radio" id="index_thumbnails_no" name="index_thumbnails" value="no" /><label for="index_thumbnails_no"> <?php echo i18n("No Create"); ?></label><br /> -<input type="radio" id="index_thumbnails_index" name="index_thumbnails" value="create" checked="checked" /><label for="index_thumbnails_index"> <?php echo i18n("Create"); ?></label><br /> -<input type="radio" id="index_thumbnails_reindex" name="index_thumbnails" value="recreate" /><label for="index_thumbnails_reindex"> <?php echo i18n("Re-create"); ?></label><br /> -<br /> - -<?php -foreach($array_meta AS $value) -{ - if($GLOBALS['linpha']->sql->config->value['sys_image_'.$value]) - { - echo strtoupper($value).":<br />"; - echo '<input type="checkbox" id="index_'.$value.'_deletefirst" name="index_'.$value.'_delete" value="delete" /><label for="index_'.$value.'_deletefirst"> '.i18n("Delete First").'</label><br />'; - echo '<input type="radio" id="index_'.$value.'_no" name="index_'.$value.'" value="no" /><label for="index_'.$value.'_no"> '.i18n("No indexing").'</label><br />'; - echo '<input type="radio" id="index_'.$value.'_index" name="index_'.$value.'" value="index" checked="checked" /><label for="index_'.$value.'_index"> '.i18n("Indexing").'</label><br />'; - echo '<br />'; - } -} - -?> -<input type="hidden" name="cmd" value="import"> -<input type="submit" name="submit" value="<?php echo i18n("Start"); ?>" /> -</form> -<br /><br /> -<?php - - -/** - * dry-run - */ -echo '<h2 class="linStyle">'.i18n("Stuff Not Up-To-Date").'</h2>'; - -/** - * import - */ - if($linpha->sql->config->value['sys_import_autoimport']) - { - LinImport::updateDir( $parent_id = 0, $recursive = true, $dryrun = true ); - } - - /** - * flush buffer - */ - echo '<b>'.i18n("Following files/folders needs updating:").'</b><br />'; - if( isset($GLOBALS['linpha']->template->output['sys_log']) ) - { - echo $GLOBALS['linpha']->template->output['sys_log']; - unset($GLOBALS['linpha']->template->output['sys_log']); - } - else - { - echo i18n("Nothing, we're up-to-date!").'<br />'; - } - - echo '<br />'; - -/** - * thumbnails - */ - $thumbnail = new LinImage(); - - $num = 0; - $query = $GLOBALS['linpha']->db->Execute("SELECT id FROM ".PREFIX."photos WHERE img_type <> 0 AND img_type <> 9999999"); - while($data = $query->FetchRow(ADODB_FETCH_NUM)) - { - - $thumbnail->mode = 'thumb'; - $thumbnail->photo_id = $data[0]; - - $thumbnail->setFileInformation(); - - if( ! $thumbnail->isCached ) - { - $num++; - } - } - echo '<b>'.i18n("Nr Thumbnails To Create:").' '.$num.'<br />'; - -/** - * exif, iptc, xmp - * - * nr images to index: (nr_total - nr_indexed) - */ - $nr_total = $GLOBALS['linpha']->db->GetRow("SELECT sum(stats_numbers) FROM ".PREFIX."photos WHERE parent_id = '0' GROUP BY parent_id"); - foreach($array_meta AS $value) - { - if($GLOBALS['linpha']->sql->config->value['sys_image_'.$value]) - { - $nr_indexed = $GLOBALS['linpha']->db->GetRow("SELECT count(md5sum) FROM ".PREFIX."meta_".$value); - - echo strtoupper($value).': '.i18n("Nr Images Needs Indexing:").' ' . ($nr_total[0] - $nr_indexed[0]) .' <br />'; - } - } -?> \ No newline at end of file Modified: trunk/linpha2/admin/index.php =================================================================== --- trunk/linpha2/admin/index.php 2006-11-09 16:05:39 UTC (rev 4629) +++ trunk/linpha2/admin/index.php 2006-11-09 22:22:06 UTC (rev 4630) @@ -78,7 +78,7 @@ //'linpha_home' => Array('name' => 'Linpha Home', 'link' => 'linpha_home'), 'settings' => Array('name' => 'Settings', 'link' => 'settings'), 'permissions' => Array('name' => 'Permissions', 'link' => 'permissions'), - 'import' => Array('name' => 'Import', 'link' => 'import'), + 'maintenance' => Array('name' => 'Maintenance', 'link' => 'maintenance'), 'imagefields' => Array('name' => 'Image fields', 'link' => 'imagefields'), ); @@ -92,8 +92,8 @@ case 'permissions': include_once('./permissions.php'); break; -case 'import': - include_once('./import.php'); +case 'maintenance': + include_once('./maintenance.php'); break; case 'imagefields': include_once('./image_fields.php'); Added: trunk/linpha2/admin/maintenance.php =================================================================== --- trunk/linpha2/admin/maintenance.php (rev 0) +++ trunk/linpha2/admin/maintenance.php 2006-11-09 22:22:06 UTC (rev 4630) @@ -0,0 +1,25 @@ +<?php +if(!defined('LINPHA_DIR')) { exit(1); } + +if(!isset($cat2)) +{ + $cat2 = 'import'; +} + +$array_menu = Array( + 'import' => Array('name' => 'Import', 'link' => 'maintenance_import'), + 'db' => Array('name' => 'Database', 'link' => 'maintenance_db'), +); + +LinAdmin::printAdminMenu($array_menu,$cat2); + +switch($cat2) +{ + case 'import': + include_once(LINPHA_DIR.'/admin/maintenance_import.php'); + break; + case 'db': + include_once(LINPHA_DIR.'/admin/maintenance_db.php'); + break; +} +?> Added: trunk/linpha2/admin/maintenance_db.php =================================================================== --- trunk/linpha2/admin/maintenance_db.php (rev 0) +++ trunk/linpha2/admin/maintenance_db.php 2006-11-09 22:22:06 UTC (rev 4630) @@ -0,0 +1,307 @@ +<?php + +/** + * check if each photo has a parent element + */ + echo '<h2>'.i18n("Checking photos table").'</h2>'; + echo '('.i18n("Checking intern consistency of the photos table. This means every entry must belong to a folder.").')<br /><br />'; + + $query = $GLOBALS['linpha']->db->Execute("SELECT id, parent_id, name FROM ".PREFIX."photos"); + $i = 0; + $i_tot = 0; + while($data = $query->FetchRow()) + { + if($data['parent_id'] != 0) + { + $query2 = $GLOBALS['linpha']->db->Execute("SELECT id FROM ".PREFIX."photos " . + "WHERE id = '".LinSql::linAddslashes($data['parent_id'])."'"); + $data2 = $query2->FetchRow(); + if( isset($data2['id'])) + { + $i++; + } + else + { + echo i18n("Warning: This entry doesn't belongs to a folder:").' '.$data['name'].'<br />'; + + /** + * @todo there should be an option where we could really delete any obsolete entries + */ + echo i18n("Should delete it").'<br />'; + } + } + else + { + $i++; + } + + $i_tot++; + } + echo sprintf(i18n("%d of %d entries are <font color='green'>ok</font>."),$i,$i_tot).'<br />'; + +/** + * check cached photos exists in filesystem and vice versa + */ + echo '<br /><h2>'.i18n("Checking image cache").'</h2>'; + + echo '<h3>'.i18n("Do all cache entries exists in the photos table?").'</h3>'; + + $query = $GLOBALS['linpha']->db->Execute("SELECT ".PREFIX."photos_cache.id, ".PREFIX."photos_cache.photo_id" . + " FROM ".PREFIX."photos_cache". + " LEFT OUTER JOIN ".PREFIX."photos ON ".PREFIX."photos.id = ".PREFIX."photos_cache.photo_id". + " WHERE ".PREFIX."photos.id IS NULL"); + + if( $query->EOF ) + { + echo '<font color="green">ok</font> '.i18n("There is no broken association.").'<br />'; + } + else + { + echo '<font color="red">failed</font><br />'; + while($data = $query->FetchRow() ) + { + echo i18n("Missing entry of:").' '.$data['photo_id'].' ('.i18n("Cache Id").': '.$data['id'].')<br />'; + } + echo '<br />'; + } + + + echo '<h3>'.i18n("Do all cache entries exists in the filesystem?").'</h3>'; + $query = $GLOBALS['linpha']->db->Execute("SELECT id, photo_id FROM ".PREFIX."photos_cache"); + $i = 0; + $i_tot = 0; + while($data = $query->FetchRow() ) + { + $filename = LinImage::getCachePath('img',$data['id'],'jpg'); + if( !file_exists($filename)) + { + echo i18n("Cached file doesn't exists:").' '.$filename.' ('.i18n("Photo Nr").': '.$data['photo_id'].')<br />'; + + /** + * @todo there should be an option where we could really delete any obsolete entries + */ + echo i18n("Should delete it").'<br />'; + } + else + { + if(filesize($filename) == 0) + { + echo i18n("Filesize is zero of:").' '.$filename.' ('.i18n("Photo Nr").': '.$data['photo_id'].')<br />'; + } + else + { + $i++; + } + } + + $i_tot++; + } + echo sprintf(i18n("%d of %d entries are <font color='green'>ok</font>."),$i,$i_tot).'<br />'; + + + echo '<br /><h3>'.i18n("Are there obsolete cached images lying around?").'</h3>'; + $path = LinSql::getPath('cache'); + $i = 0; + $i_tot = 0; + $sub_dir_handle = opendir($path.'/img'); + while( ($sub_dir = readdir($sub_dir_handle)) !== false ) + { + if($sub_dir != "." && $sub_dir != "..") + { + $sub_file_handle = opendir($path.'/img/'.$sub_dir); + while( ($sub_file = readdir($sub_file_handle)) !== false ) + { + if($sub_file != "." && $sub_file != "..") + { + $filename_without_ext = LinFilesys::getFilenameWithoutFileExt($sub_file); + + /** + * need this pre check because mysql returns a result even if id is '107.' + * testquery: "SELECT * FROM linpha_photos WHERE id = '107.'" + */ + if(! preg_match('/^[0-9]*$/', $filename_without_ext)) + { + echo i18n("Obsolete cached file:").' '.$path.'/img/'.$sub_dir.'/'.$sub_file.'<br />'; + } + else + { + $query = $GLOBALS['linpha']->db->Execute("SELECT id FROM ".PREFIX."photos_cache WHERE " . + "id = '".LinSql::linAddslashes( LinFilesys::getFilenameWithoutFileExt($sub_file) )."'"); + $data = $query->FetchRow(); + + if( isset($data['id'])) + { + $i++; + } + else + { + echo i18n("Obsolete cached file:").' '.$path.'/img/'.$sub_dir.'/'.$sub_file.'<br />'; + } + } + + $i_tot++; + } + } + + closedir($sub_file_handle); + } + } + closedir($sub_dir_handle); + echo sprintf(i18n("%d of %d entries are <font color='green'>ok</font>."),$i,$i_tot).'<br />'; + + + echo '<br /><h3>'.i18n("Are there obsolete cached thumbnails lying around?").'</h3>'; + $path = LinSql::getPath('cache'); + $i = 0; + $i_tot = 0; + $sub_dir_handle = opendir($path.'/thumb'); + while( ($sub_dir = readdir($sub_dir_handle)) !== false ) + { + if($sub_dir != "." && $sub_dir != "..") + { + $sub_file_handle = opendir($path.'/thumb/'.$sub_dir); + while( ($sub_file = readdir($sub_file_handle)) !== false ) + { + if($sub_file != "." && $sub_file != "..") + { + $filename_without_ext = LinFilesys::getFilenameWithoutFileExt($sub_file); + + /** + * need this pre check because mysql returns a result even if id is '107.' + * testquery: "SELECT * FROM linpha_photos WHERE id = '107.'" + */ + if(! preg_match('/^[0-9]*$/', $filename_without_ext)) + { + echo i18n("Obsolete cached file:").' '.$path.'/img/'.$sub_dir.'/'.$sub_file.'<br />'; + } + else + { + $query = $GLOBALS['linpha']->db->Execute("SELECT name FROM ".PREFIX."photos WHERE " . + "id = '".LinSql::linAddslashes( $filename_without_ext )."'"); + $data = $query->FetchRow(); + + if( isset($data['name'])) + { + $i++; + } + else + { + echo i18n("Obsolete cached file:").' '.$path.'/img/'.$sub_dir.'/'.$sub_file.'<br />'; + } + } + + $i_tot++; + } + } + + closedir($sub_file_handle); + } + } + closedir($sub_dir_handle); + echo sprintf(i18n("%d of %d entries are <font color='green'>ok</font>."),$i,$i_tot).'<br />'; + +/** + * check comment/exif/iptc/xmp to photo association + */ + echo '<br /><h2>'.i18n("Checking meta data").'</h2>'; + $array_meta = array('comments','data','exif','iptc'/*,'xmp'*/); + foreach($array_meta AS $value) + { + echo i18n("Checking table").' '.PREFIX."meta_".$value.' '; + $query = $GLOBALS['linpha']->db->Execute("SELECT ".PREFIX."meta_".$value.".md5sum FROM ".PREFIX."meta_".$value. + " LEFT OUTER JOIN ".PREFIX."photos ON ".PREFIX."photos.md5sum = ".PREFIX."meta_".$value.".md5sum". + " WHERE ".PREFIX."photos.id IS NULL"); + + if( $query->EOF ) + { + echo '<font color="green">ok</font>'.'<br />'; + } + else + { + echo '<font color="red">failed</font><br />'; + while($data = $query->FetchRow() ) + { + echo i18n("Missing entry with md5sum:").' '.$data['md5sum'].'<br />'; + } + echo '<br />'; + } + } + + +/** + * check permission entries + */ + $array_perms = array( + 'read', + 'write', + 'basket_print', + 'basket_mail', + 'basket_download', + 'metadata_comments', + 'metadata_deletecomments', + 'metadata_edit', + 'watermark', + 'stats', + 'download', + ); + + echo '<br /><h2>'.i18n("Checking permission entries").'</h2>'; + + foreach($array_perms AS $value) + { + $query = $GLOBALS['linpha']->db->Execute("SELECT permission FROM ".PREFIX."permissions " . + "WHERE photos_id = '0' AND perm_type = '".$value."'"); + $data = $query->FetchRow(); + + echo i18n("Checking").' "'.$value.'" '; + if( isset($data['permission']) ) + { + echo '<font color="green">'.i18n("ok").'</font>'; + } + else + { + echo '<font color="red">'.i18n("failed").'</font><br />'; + echo i18n("Please check the database, these entry is missing!").'<br />'; + } + echo '<br />'; + } + +/** + * checking config entries + */ + echo '<br /><h2>'.i18n("Checking config entries").'</h2>'; + + /** + * prevent some php notices + */ + $options = array(); + $_SESSION['sys_im_bracket_support'] = ''; + $_SESSION['sys_im_use_convert'] = ''; + $_SESSION['sys_im_convert_path'] = ''; + $_SESSION['language'] = ''; + $_SESSION['album_dir'] = ''; + $_SESSION['cache_dir'] = ''; + $_SESSION['tmp_dir'] = ''; + + include(LINPHA_DIR.'/install/sql/sql.data.php'); + foreach($options AS $key=>$value) + { + $query = $GLOBALS['linpha']->db->Execute("SELECT id FROM ".PREFIX."config " . + "WHERE option_name = '".$key."'"); + $data = $query->FetchRow(); + + echo i18n("Checking").' "'.$key.'" '; + if( isset($data['id']) ) + { + echo '<font color="green">'.i18n("ok").'</font>'; + } + else + { + echo '<font color="red">'.i18n("failed").'</font><br />'; + echo i18n("Please check the database, these entry is missing!").'<br />'; + } + echo '<br />'; + } + + +?> \ No newline at end of file Copied: trunk/linpha2/admin/maintenance_import.php (from rev 4623, trunk/linpha2/admin/import.php) =================================================================== --- trunk/linpha2/admin/maintenance_import.php (rev 0) +++ trunk/linpha2/admin/maintenance_import.php 2006-11-09 22:22:06 UTC (rev 4630) @@ -0,0 +1,426 @@ +<?php +/* +* Copyright (c) 2005 Heiko Rutenbeck <bz...@tu...> +* Florian Angehrn +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +/** + * This file updates the database + * @package Import + */ + +if(!defined('LINPHA_DIR')) { exit(1); } + +/** + * try it, it works sometimes + */ +ini_set("max_execution_time", "6000"); + + +$array_meta = Array('exif','iptc','xmp'); + +if( isset($_POST['cmd']) && $_POST['cmd']=='import') +{ + echo '<h1 class="linStyle">'.i18n("Running Import...").'</h1>'; + + if(!isset($_REQUEST['album_select']) OR $_REQUEST['album_select'][0]=='all') + { + $all_albums = true; + } + else + { + $all_albums = false; + } + + + /** + * import + */ + if($_REQUEST['index_import']=='index') + { + echo '<h2 class="linStyle">'.i18n("Directory Import").'</h2>'; + if($all_albums) + { + echo i18n("Parsing All Directories...").'<br />'; + LinImport::updateDir( $parent_id = 0, $recursive = true, $dryrun = false ); + } + else + { + foreach($_REQUEST['album_select'] AS $key=>$value) + { + $data = $GLOBALS['linpha']->db->GetRow("SELECT name FROM ".PREFIX."photos WHERE id = '".LinSql::linAddslashes($value)."'"); + echo i18n("Parsing Directory:").' '.$data['name'].'<br />'; + LinImport::updateDir( $parent_id = $value, $recursive = true, $dryrun = false ); + } + } + + if( isset($GLOBALS['linpha']->template->output['sys_log']) ) + { + echo $GLOBALS['linpha']->template->output['sys_log']; + unset($GLOBALS['linpha']->template->output['sys_log']); + } + + echo '<br />'; + } + + /** + * thumbnails + */ + /** + * @todo should we create the folder thumbnails here? + * they will be automatically created on each visit + * we would have to take care to the script backwards, + * that means first of the depest subfolder until we're on top + */ + if($_REQUEST['index_thumbnails']!='no' OR isset($_REQUEST['index_thumbnails_delete'])) + { + echo '<h2 class="linStyle">'.i18n("Thumbnails").'</h2>'; + + $thumbnail = new LinImage(); + + if($_REQUEST['index_thumbnails']=='recreate') + { + $_GET['force'] = true; + } + + /** + * all albums selected + */ + if($all_albums) + { + /** + * delete thumbnails + */ + if( isset($_REQUEST['index_thumbnails_delete']) ) + { + echo i18n("Delete All Existing Thumbnails...").'<br />'; + $thumbcachepath = LinSql::getPath('cache').'/thumb'; + LinFilesys::rm_rf( $thumbcachepath ); // all subfolders will automatically be recreated on each image access + if(file_exists($thumbcachepath)) + { + echo i18n("Warning while deleting file/folder, check permissions!").'<br />'; + } + else + { + mkdir( $thumbcachepath ); + } + } + + /** + * set query string for create/recreate thumbnails + */ + if($_REQUEST['index_thumbnails']!='no') + { + echo '<h3>'.i18n("Parsing All Directories...").'</h3><br />'; + $createthumbquery = $GLOBALS['linpha']->db->Execute("SELECT id FROM ".PREFIX."photos WHERE img_type <> 0 AND img_type <> 9999999"); + } + } + else // $all_albums == false -> not all directory selected + { + /** + * go through each selected directory + */ + foreach($_REQUEST['album_select'] AS $key=>$value) + { + $data = $GLOBALS['linpha']->db->GetRow("SELECT name FROM ".PREFIX."photos WHERE id = '".LinSql::linAddslashes($value)."'"); + echo i18n("Parsing Directory:").' '.$data['name'].'<br />'; + + $sql = "SELECT id FROM ".PREFIX."photos WHERE " . + "parent_id = '".LinSql::linAddslashes($value)."' AND " . + "img_type <> 0 AND img_type <> 9999999"; + + /** + * delete thumbnails + */ + if( isset($_REQUEST['index_thumbnails_delete']) ) + { + echo i18n("Delete Thumbnails"); + $query = $GLOBALS['linpha']->db->Execute($sql); + while($data = $query->FetchRow(ADODB_FETCH_NUM)) + { + if( LinImage::deleteCachedThumbnail($data[0]) ) + { + echo " ".$data[0].","; + } + } + echo '<br />'; + } + + /** + * set query string for create/recreate thumbnails + */ + if($_REQUEST['index_thumbnails']!='no') + { + $createthumbquery = $GLOBALS['linpha']->db->Execute($sql); + } + } + } + + /** + * now create thumbnails, $query has been set previously + */ + if($_REQUEST['index_thumbnails']!='no') + { + echo i18n("Create Thumbnail"); + while($data = $createthumbquery->FetchRow(ADODB_FETCH_NUM)) + { + if( ! $thumbnail->createThumbnail($data[0]) ) + { + echo i18n("Error While Creating Thumbnail!")."<br />Error: ".$thumbnail->error_msg."<br />"; + } + if( ! $thumbnail->isCached ) // thumbnail wasn't cached -> now created! + { + echo " ".$data[0].","; + } + flush(); + } + echo '<br />'; + } + + echo '<br />'; + } + + + /** + * exif, iptc, xmp + * + * if "Delete First" and "All albums" was selected, the whole table will be deleted + */ + include_once(LINPHA_DIR.'/lib/classes/linpha.metadata.class.php'); + $MetaData = new MetaData(); + + foreach($array_meta AS $meta_value) + { + if( isset( $_REQUEST['index_'.$meta_value] ) && + ( $_REQUEST['index_'.$meta_value] == 'index' OR isset($_REQUEST['index_'.$meta_value.'_delete']) ) ) + { + echo '<h2 class="linStyle">'.i18n("File Indexing").' ('.strtoupper($meta_value).')</h2>'; + + /** + * get imgids to indexing, if reindex is selected: delete these entries first + */ + if($all_albums) + { + echo i18n("All Directories selected").'<br />'; + + $query = $GLOBALS['linpha']->db->Execute("SELECT id, md5sum FROM ".PREFIX."photos WHERE img_type <> 0 AND img_type <> 9999999"); + while($data = $query->FetchRow()) + { + $array_meta_ids[$data['id']] = $data['md5sum']; + } + } + else + { + echo i18n("Directory selected:").' '; + foreach($_REQUEST['album_select'] AS $key=>$value) + { + $data = $GLOBALS['linpha']->db->GetRow("SELECT name FROM ".PREFIX."photos WHERE id = '".LinSql::linAddslashes($value)."'"); + echo $data['name'].', '; + + $query = $GLOBALS['linpha']->db->Execute("SELECT id, md5sum FROM ".PREFIX."photos WHERE " . + "parent_id = '".LinSql::linAddslashes($value)."' AND " . + "img_type <> 0 AND img_type <> 9999999"); + while($data = $query->FetchRow(ADODB_FETCH_NUM)) + { + $array_meta_ids[$data['id']] = $data['md5sum']; + } + } + echo '<br />'; + } + + /** + * delete first (if selected) + */ + if( isset($_REQUEST['index_'.$meta_value.'_delete']) ) + { + if( $all_albums ) + { + echo i18n("Delete all index data").'<br />'; + $GLOBALS['linpha']->db->Execute("DELETE FROM ".PREFIX."meta_".$meta_value); + } + elseif( isset($array_meta_ids) ) + { + echo i18n("Delete index data of selected directories").'<br />'; + foreach($array_meta_ids AS $id=>$md5sum) + { + $GLOBALS['linpha']->db->Execute("DELETE FROM ".PREFIX."meta_".$meta_value." WHERE md5sum = '".$md5sum."'"); + } + } + } + + /** + * index image, parse all saved ids + */ + if( isset($array_meta_ids) && $_REQUEST['index_'.$meta_value] == 'index' ) + { + $MetaData->setFields($meta_value); + + echo i18n("Index Image"); + + foreach($array_meta_ids AS $id=>$md5sum) + { + $query = $GLOBALS['linpha']->db->Execute("SELECT md5sum ". + "FROM ".PREFIX."meta_exif WHERE md5sum = '".$md5sum."'"); + + if( $query->EOF) // not a single value returned + { + $full_filename = LinSql::getFullImagePath($id); + + switch($meta_value) + { + case 'exif': + include_once(LINPHA_DIR.'/lib/classes/phpmeta/JPEG.php'); // used for jpeg comment + include_once(LINPHA_DIR.'/lib/classes/phpmeta/EXIF.php'); + $MetaData->saveExifData( $full_filename,$md5sum ); + break; + case 'iptc': + include_once(LINPHA_DIR.'/lib/classes/phpmeta/Photoshop_IRB.php'); + include_once(LINPHA_DIR.'/lib/classes/phpmeta/JPEG.php'); + $MetaData->saveIptcData( $full_filename,$md5sum ); + break; + case 'xmp': + break; + } + + echo " ".$id.","; + flush(); + } + } + + } + + echo '<br /><br />'; + } + unset($array_meta_ids); + } +} + + +echo '<h1 class="linStyle">'.i18n("Import").'</h1>'; +echo i18n("Select Folders For Import/Update:"); +?> +<br /> +<form action="./?cat=import" method="POST"> +<select name="album_select[]" size="10" multiple="multiple" style="width: 500px;"> +<?php linBuildAlbumSelect($with_all_albs_entry=true); ?> +</select> +<br /><br /> + +<?php echo i18n("Import").':'; ?> +<br /> + +<input type="checkbox" id="index_import_detect_filechanges" name="force_update" value="true" /><label for="index_import_detect_filechanges"> <?php echo i18n("Detect File Changes"); ?></label><br /> +<input type="radio" id="index_import_no" name="index_import" value="no" /><label for="index_import_no"> <?php echo i18n("No Import"); ?></label><br /> +<input type="radio" id="index_import_index" name="index_import" value="index" checked="checked" /><label for="index_import_index"> <?php echo i18n("Import"); ?></label><br /> +<br /> + +<?php echo i18n("Thumbnails").':'; ?> +<br /> +<input type="checkbox" id="index_thumbnails_deletefirst" name="index_thumbnails_delete" value="delete" /><label for="index_thumbnails_deletefirst"> <?php echo i18n("Delete First"); ?></label><br /> +<input type="radio" id="index_thumbnails_no" name="index_thumbnails" value="no" /><label for="index_thumbnails_no"> <?php echo i18n("No Create"); ?></label><br /> +<input type="radio" id="index_thumbnails_index" name="index_thumbnails" value="create" checked="checked" /><label for="index_thumbnails_index"> <?php echo i18n("Create"); ?></label><br /> +<input type="radio" id="index_thumbnails_reindex" name="index_thumbnails" value="recreate" /><label for="index_thumbnails_reindex"> <?php echo i18n("Re-create"); ?></label><br /> +<br /> + +<?php +foreach($array_meta AS $value) +{ + if($GLOBALS['linpha']->sql->config->value['sys_image_'.$value]) + { + echo strtoupper($value).":<br />"; + echo '<input type="checkbox" id="index_'.$value.'_deletefirst" name="index_'.$value.'_delete" value="delete" /><label for="index_'.$value.'_deletefirst"> '.i18n("Delete First").'</label><br />'; + echo '<input type="radio" id="index_'.$value.'_no" name="index_'.$value.'" value="no" /><label for="index_'.$value.'_no"> '.i18n("No indexing").'</label><br />'; + echo '<input type="radio" id="index_'.$value.'_index" name="index_'.$value.'" value="index" checked="checked" /><label for="index_'.$value.'_index"> '.i18n("Indexing").'</label><br />'; + echo '<br />'; + } +} + +?> +<input type="hidden" name="cmd" value="import"> +<input type="submit" name="submit" value="<?php echo i18n("Start"); ?>" /> +</form> +<br /><br /> +<?php + + +/** + * dry-run + */ +echo '<h2 class="linStyle">'.i18n("Stuff Not Up-To-Date").'</h2>'; + +/** + * import + */ + if($linpha->sql->config->value['sys_import_autoimport']) + { + LinImport::updateDir( $parent_id = 0, $recursive = true, $dryrun = true ); + } + + /** + * flush buffer + */ + echo '<b>'.i18n("Following files/folders needs updating:").'</b><br />'; + if( isset($GLOBALS['linpha']->template->output['sys_log']) ) + { + echo $GLOBALS['linpha']->template->output['sys_log']; + unset($GLOBALS['linpha']->template->output['sys_log']); + } + else + { + echo i18n("Nothing, we're up-to-date!").'<br />'; + } + + echo '<br />'; + +/** + * thumbnails + */ + $thumbnail = new LinImage(); + + $num = 0; + $query = $GLOBALS['linpha']->db->Execute("SELECT id FROM ".PREFIX."photos WHERE img_type <> 0 AND img_type <> 9999999"); + while($data = $query->FetchRow(ADODB_FETCH_NUM)) + { + + $thumbnail->mode = 'thumb'; + $thumbnail->photo_id = $data[0]; + + $thumbnail->setFileInformation(); + + if( ! $thumbnail->isCached ) + { + $num++; + } + } + echo '<b>'.i18n("Nr Thumbnails To Create:").' '.$num.'<br />'; + +/** + * exif, iptc, xmp + * + * nr images to index: (nr_total - nr_indexed) + */ + $nr_total = $GLOBALS['linpha']->db->GetRow("SELECT sum(stats_numbers) FROM ".PREFIX."photos WHERE parent_id = '0' GROUP BY parent_id"); + foreach($array_meta AS $value) + { + if($GLOBALS['linpha']->sql->config->value['sys_image_'.$value]) + { + $nr_indexed = $GLOBALS['linpha']->db->GetRow("SELECT count(md5sum) FROM ".PREFIX."meta_".$value); + + echo strtoupper($value).': '.i18n("Nr Images Needs Indexing:").' ' . ($nr_total[0] - $nr_indexed[0]) .' <br />'; + } + } +?> \ No newline at end of file Modified: trunk/linpha2/docs/dev/TODO.txt =================================================================== --- trunk/linpha2/docs/dev/TODO.txt 2006-11-09 16:05:39 UTC (rev 4629) +++ trunk/linpha2/docs/dev/TODO.txt 2006-11-09 22:22:06 UTC (rev 4630) @@ -12,7 +12,10 @@ - Installer - define final installer behaviour - - if installation is complete, the user must delete the install/ folder ? (install/ignore_delete_install_msg.txt) + - if installation is complete, the user must delete the install/ folder ? + (install/ignore_delete_install_msg.txt) + -> we need to move the sql scripts to the /lib folder because we need them + in the admin - maintenance - db part - user have to delete var/sql/config.sql.php before another installation can continue ? -> otherwise it would be possible to overwrite the current installation, (and to delete cache folders) - DONT add feature to drop tables if they already exists Modified: trunk/linpha2/lib/classes/linpha.filesys.class.php =================================================================== --- trunk/linpha2/lib/classes/linpha.filesys.class.php 2006-11-09 16:05:39 UTC (rev 4629) +++ trunk/linpha2/lib/classes/linpha.filesys.class.php 2006-11-09 22:22:06 UTC (rev 4630) @@ -238,6 +238,26 @@ } /** + * gets the filename withouth the file extension (index.html > index) + * + * @author flo + * @param string $filename + * @return string filename without file extension + * @package filesys + * @uses admin/maintenance_db.php + */ +function getFilenameWithoutFileExt($filename) +{ + if(substr_count($filename,'.') == 0) { + return $filename; // no point found, -> is already filename without the extension + } + $pos = strrpos( $filename, '.' ); // find last point + $filename = substr( $filename, 0, $pos ); // extract filename + + return $filename; +} + +/** * This function formats the filesize (byte) value to kB/MB/GB */ function niceFilesize($filesize, $precision) Modified: trunk/linpha2/lib/classes/linpha.functions.php =================================================================== --- trunk/linpha2/lib/classes/linpha.functions.php 2006-11-09 16:05:39 UTC (rev 4629) +++ trunk/linpha2/lib/classes/linpha.functions.php 2006-11-09 22:22:06 UTC (rev 4630) @@ -330,8 +330,6 @@ /** * explode string to array and remove first and last entry of array because they are empty - * - * should be moved to "others" */ function linExplodeAndSlice($del,$string) { Modified: trunk/linpha2/lib/classes/linpha.image.class.php =================================================================== --- trunk/linpha2/lib/classes/linpha.image.class.php 2006-11-09 16:05:39 UTC (rev 4629) +++ trunk/linpha2/lib/classes/linpha.image.class.php 2006-11-09 22:22:06 UTC (rev 4630) @@ -490,7 +490,7 @@ * @todo use img_type as parameter and decide in this function * which file extension to use */ -function getCachePath($what,$id,$ext='.jpg') +function getCachePath($what,$id,$ext='jpg') { $path = LinSql::getPath('cache'); Modified: trunk/linpha2/lib/classes/linpha.imgview.class.php =================================================================== --- trunk/linpha2/lib/classes/linpha.imgview.class.php 2006-11-09 16:05:39 UTC (rev 4629) +++ trunk/linpha2/lib/classes/linpha.imgview.class.php 2006-11-09 22:22:06 UTC (rev 4630) @@ -279,7 +279,7 @@ array( 'name' => i18n("Import"), 'value' => array( - array('name' => i18n("Start Import Of This Folder/File"), 'value' => LINPHA_CLIENT.'/admin/?cat=import&album_select[]='.$this->id_parent), + array('name' => i18n("Start Import Of This Folder/File"), 'value' => LINPHA_CLIENT.'/admin/?cat=maintenance_import&album_select[]='.$this->id_parent), array('name' => i18n("Detect File Changes"), 'value' => $GLOBALS['linpha']->template->URL_full.'&force_update') ) ); @@ -601,6 +601,7 @@ /** * create thumbnail info text (filename, description, etc.) */ + $i=0; foreach($this->photos_filtered AS $key=>$photo_value) { $GLOBALS['linpha']->template->output['thumb_infos'][$photo_value['id']]['before'] = ''; @@ -630,22 +631,22 @@ } else { + $i++; if($index == 'before') { $GLOBALS['linpha']->template->output['thumb_infos'][$photo_value['id']]['before'] .= $value['value'].'<br />'; // $value['value'] is already escaped - $i++; } elseif($index == 'after') { $GLOBALS['linpha']->template->output['thumb_infos'][$photo_value['id']]['after'] .= $value['value'].'<br />'; // $value['value'] is already escaped - $i++; } } } - $this->nr_text_lines = $i; // used in LinThumbnails.js to calculate the space for the thumb height $GLOBALS['linpha']->template->output['thumb_infos'][$photo_value['id']]['title'] = $photo_value['name']; // $photo_value['name'] is already escaped } + + $this->nr_text_lines = $i; // used in LinThumbnails.js to calculate the space for the thumb height /** Modified: trunk/linpha2/lib/classes/linpha.sql.class.php =================================================================== --- trunk/linpha2/lib/classes/linpha.sql.class.php 2006-11-09 16:05:39 UTC (rev 4629) +++ trunk/linpha2/lib/classes/linpha.sql.class.php 2006-11-09 22:22:06 UTC (rev 4630) @@ -480,7 +480,8 @@ } else { - $data = $GLOBALS['linpha']->db->GetRow("SELECT parent_id FROM ".PREFIX."photos WHERE id = '".LinSql::linAddslashes($photos_id)."'"); + $data = $GLOBALS['linpha']->db->GetRow("SELECT parent_id FROM ".PREFIX."photos " . + "WHERE id = '".LinSql::linAddslashes($photos_id)."'"); if( isset( $data[0] ) ) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |