diff --git a/framework/modules/administration/controllers/administrationController.php b/framework/modules/administration/controllers/administrationController.php index 1d45730f44..5108130321 100755 --- a/framework/modules/administration/controllers/administrationController.php +++ b/framework/modules/administration/controllers/administrationController.php @@ -32,7 +32,92 @@ function hasViews() { return true; } function hasContent() { return true; } function supportsWorkflow() { return false; } function isSearchable() { return false; } - + + + public function install_tables() { + global $db; + + define("TMP_TABLE_EXISTED", 1); + define("TMP_TABLE_INSTALLED", 2); + define("TMP_TABLE_FAILED", 3); + define("TMP_TABLE_ALTERED", 4); + + $dirs = array( + BASE."datatypes/definitions", + BASE."framework/core/database/definitions", + ); + + $tables = array(); + foreach ($dirs as $dir) { + if (is_readable($dir)) { + $dh = opendir($dir); + while (($file = readdir($dh)) !== false) { + if (is_readable("$dir/$file") && is_file("$dir/$file") && substr($file,-4,4) == ".php" && substr($file,-9,9) != ".info.php") { + $tablename = substr($file,0,-4); + $dd = include("$dir/$file"); + $info = null; + if (is_readable("$dir/$tablename.info.php")) $info = include("$dir/$tablename.info.php"); + if (!$db->tableExists($tablename)) { + foreach ($db->createTable($tablename,$dd,$info) as $key=>$status) { + $tables[$key] = $status; + } + } else { + foreach ($db->alterTable($tablename,$dd,$info) as $key=>$status) { + if (isset($tables[$key])) echo "$tablename, $key
"; + if ($status == TABLE_ALTER_FAILED){ + $tables[$key] = $status; + }else{ + $tables[$key] = ($status == TABLE_ALTER_NOT_NEEDED ? DATABASE_TABLE_EXISTED : DATABASE_TABLE_ALTERED); + } + + } + } + } + } + } + } + + $newdef = BASE."framework/modules"; + + if (is_readable($newdef)) { + $dh = opendir($newdef); + while (($file = readdir($dh)) !== false) { + if (is_dir($newdef.'/'.$file) && ($file != '..' && $file != '.')) { + $dirpath = $newdef.'/'.$file.'/definitions'; + if (file_exists($dirpath)) { + $def_dir = opendir($dirpath); + while (($def = readdir($def_dir)) !== false) { + eDebug("$dirpath/$def"); + if (is_readable("$dirpath/$def") && is_file("$dirpath/$def") && substr($def,-4,4) == ".php" && substr($def,-9,9) != ".info.php") { + $tablename = substr($def,0,-4); + $dd = include("$dirpath/$def"); + $info = null; + if (is_readable("$dirpath/$tablename.info.php")) $info = include("$dirpath/$tablename.info.php"); + if (!$db->tableExists($tablename)) { + foreach ($db->createTable($tablename,$dd,$info) as $key=>$status) { + $tables[$key] = $status; + } + } else { + foreach ($db->alterTable($tablename,$dd,$info) as $key=>$status) { + if (isset($tables[$key])) echo "$tablename, $key
"; + if ($status == TABLE_ALTER_FAILED){ + $tables[$key] = $status; + }else{ + $tables[$key] = ($status == TABLE_ALTER_NOT_NEEDED ? DATABASE_TABLE_EXISTED : DATABASE_TABLE_ALTERED); + } + + } + } + } + } + } + } + } + } + ksort($tables); + assign_to_template(array('status'=>$tables)); + } + public function manage_unused_tables() { global $db; @@ -65,7 +150,140 @@ public function delete_unused_tables() { flash('message', 'Deleted '.$count.' unused tables.'); expHistory::back(); } - + + public function optimize_database() { + global $db; + + $before = $db->databaseInfo(); + foreach (array_keys($before) as $table) { + $db->optimize($table); + } + $after = $db->databaseInfo(); + assign_to_template(array('before'=>$before,'after'=>$after)); + } + + public function fix_sessions() { + global $db; + +// $test = $db->sql('CHECK TABLE '.DB_TABLE_PREFIX.'sessionticket'); + $fix = $db->sql('REPAIR TABLE '.DB_TABLE_PREFIX.'sessionticket'); + flash('message', 'Sessions Table was Repaired'); + expHistory::back(); + } + + + public function fix_database() { + global $db; + + print_r("

Attempting to Fix the Exponent Database

"); + print_r("

Some Error Conditions can NOT be repaired by this Procedure!


"); + print_r("
");
+	// upgrade sectionref's that have lost their originals
+		print_r("Searching for sectionrefs that have lost their originals

"); + $sectionrefs = $db->selectObjects('sectionref',"is_original=0"); + if (count($sectionrefs)) { + print_r("Found: ".count($sectionrefs)." copies (not originals)
"); + } else { + print_r("None Found: Good!
"); + } + foreach ($sectionrefs as $sectionref) { + if ($db->selectObject('sectionref',"module='".$sectionref->module."' AND source='".$sectionref->source."' AND is_original='1'") == null) { + // There is no original for this sectionref so change it to the original + $sectionref->is_original = 1; + $db->updateObject($sectionref,"sectionref"); + print_r("Fixed: ".$sectionref->module." - ".$sectionref->source."
"); + } + } + print_r("
"); + + print_r("
");
+	// upgrade sectionref's that point to missing sections (pages)
+		print_r("Searching for sectionrefs pointing to missing sections/pages 
to fix for the Recycle Bin


"); + $sectionrefs = $db->selectObjects('sectionref',"refcount!=0"); + $found = 0; + foreach ($sectionrefs as $sectionref) { + if ($db->selectObject('section',"id='".$sectionref->section."'") == null) { + // There is no section/page for sectionref so change the refcount + $sectionref->refcount = 0; + $db->updateObject($sectionref,"sectionref"); + print_r("Fixed: ".$sectionref->module." - ".$sectionref->source."
"); + $found += 1; + } + } + if (!$found) { + print_r("None Found: Good!
"); + } + print_r("
"); + +// FIXME Not needed when locationrefs are removed + print_r("
");
+	 // add missing locationref's based on existing sectionref's
+		 print_r("Searching for detached modules with no original (no matching locationref)

"); + $sectionrefs = $db->selectObjects('sectionref',1); + foreach ($sectionrefs as $sectionref) { + if ($db->selectObject('locationref',"module='".$sectionref->module."' AND source='".$sectionref->source."'") == null) { + // There is no locationref for sectionref. Populate reference + $newLocRef = null; + $newLocRef->module = $sectionref->module; + $newLocRef->source = $sectionref->source; + $newLocRef->internal = $sectionref->internal; + $newLocRef->refcount = $sectionref->refcount; + $db->insertObject($newLocRef,'locationref'); + print_r("Copied: ".$sectionref->module." - ".$sectionref->source."
"); + } + } + print_r("
"); + + print_r("
");
+	 // delete sectionref's & locationref's that have empty sources since they are dead
+		 print_r("Searching for unassigned modules (no source)

"); + $sectionrefs = $db->selectObjects('sectionref','source=""'); + if ($sectionrefs != null) { + print_r("Removing: ".count($sectionrefs)." empty sectionref's (no source)
"); + $db->delete('sectionref','source=""'); + } else { + print_r("No Empties Found: Good!
"); + } +// FIXME Not needed when locationrefs are removed + $locationrefs = $db->selectObjects('locationref','source=""'); + if ($locationrefs != null) { + print_r("Removing: ".count($locationrefs)." empty locationref's (no source)
"); + $db->delete('locationref','source=""'); + } else { + print_r("No Empties Found: Good!
"); + } + print_r("
"); + + print_r("
");
+	// add missing sectionrefs based on existing containers (fixes aggregation problem)
+		print_r("Searching for missing sectionref's based on existing container's

"); + $containers = $db->selectObjects('container',1); + foreach ($containers as $container) { + $iloc = expUnserialize($container->internal); + if ($db->selectObject('sectionref',"module='".$iloc->mod."' AND source='".$iloc->src."'") == null) { + // There is no sectionref for this container. Populate sectionref + $newSecRef = null; + $newSecRef->module = $iloc->mod; + $newSecRef->source = $iloc->src; + $newSecRef->internal = ''; + $newSecRef->refcount = 1; + $newSecRef->is_original = 1; + if ($container->external != "N;") { + $eloc = expUnserialize($container->external); + $section = $db->selectObject('sectionref',"module='containermodule' AND source='".$eloc->src."'"); + if (!empty($section)) { + $newSecRef->section = $section->id; + $db->insertObject($newSecRef,"sectionref"); + print_r("Missing sectionref for container replaced: ".$iloc->mod." - ".$iloc->src." - PageID #".$section->id."
"); + } else { + print_r("Cant' find the container page for container: ".$iloc->mod." - ".$iloc->src."
"); + } + } + } + } + print_r("
"); + } + public function toolbar() { global $user; $menu = array(); @@ -115,6 +333,176 @@ public function toggle_minify() { expHistory::back(); } + public function toggle_dev() { + if (!defined('SYS_CONFIG')) include_once(BASE.'subsystems/config.php'); + $value = (DEVELOPMENT == 1) ? 0 : 1; + exponent_config_change('DEVELOPMENT', $value); + exponent_theme_remove_css(); + $message = (DEVELOPMENT != 1) ? "Exponent is now in 'Development' mode" : "Exponent is no longer in 'Development' mode" ; + flash('message',$message); + expHistory::back(); + } + + public function toggle_maintenance() { + if (!defined('SYS_CONFIG')) include_once(BASE.'subsystems/config.php'); + $value = (MAINTENANCE_MODE == 1) ? 0 : 1; + exponent_config_change('MAINTENANCE_MODE', $value); + MAINTENANCE_MODE == 1 ? flash('message',"Exponent is no longer in 'Maintenance' mode") : "" ; + expHistory::back(); + } + + public function clear_smarty_cache() { + exponent_theme_remove_smarty_cache(); + $message = "Smarty Cache has been cleared" ; + flash('message',$message); + expHistory::back(); + } + + public function clear_css_cache() { + exponent_theme_remove_css(); + $message = "CSS/Minfy Cache has been cleared" ; + flash('message',$message); + expHistory::back(); + } + + public function clear_image_cache() { + if (!defined('SYS_FILES')) include_once(BASE.'subsystems/files.php'); + exponent_files_remove_files_in_directory(BASE.'tmp/pixidou'); // alt location for cache + // phpThumb cache includes subfolders + if (file_exists(BASE.'tmp/img_cache')) exponent_files_remove_files_in_directory(BASE.'tmp/img_cache'); + $message = "Image/Pixidou Cache has been cleared" ; + flash('message',$message); + expHistory::back(); + } + + public function clear_rss_cache() { + if (!defined('SYS_FILES')) include_once(BASE.'subsystems/files.php'); + exponent_files_remove_files_in_directory(BASE.'tmp/rsscache'); + $message = "RSS/Podcast Cache has been cleared" ; + flash('message',$message); + expHistory::back(); + } + + public function clear_all_caches() { + if (!defined('SYS_FILES')) include_once(BASE.'subsystems/files.php'); + exponent_theme_remove_smarty_cache(); + exponent_theme_remove_css(); + exponent_files_remove_files_in_directory(BASE.'tmp/pixidou'); // alt location for cache + if (file_exists(BASE.'tmp/img_cache')) exponent_files_remove_files_in_directory(BASE.'tmp/img_cache'); + exponent_files_remove_files_in_directory(BASE.'tmp/rsscache'); + $message = "All the System Caches have been cleared" ; + flash('message',$message); + expHistory::back(); + } + + public function upload_extension() { + if (!defined('SYS_FORMS')) require_once(BASE.'subsystems/forms.php'); + exponent_forms_initialize(); + $form = new form(); + $form->register(null,'',new htmlcontrol(exponent_core_maxUploadSizeMessage())); + $form->register('mod_archive','Module Archive',new uploadcontrol()); + $form->register('submit','',new buttongroupcontrol('Install')); + $form->meta('module','administration'); + $form->meta('action','install_extension'); + + assign_to_template(array('form_html'=>$form->toHTML())); + } + + public function install_extension() { + + $i18n = exponent_lang_loadFile('modules/administrationmodule/actions/install_extension.php'); + if ($_FILES['mod_archive']['error'] != UPLOAD_ERR_OK) { + switch($_FILES['mod_archive']['error']) { + case UPLOAD_ERR_INI_SIZE: + case UPLOAD_ERR_FORM_SIZE: + echo $i18n['file_too_large'].'
'; + break; + case UPLOAD_ERR_PARTIAL: + echo $i18n['partial_file'].'
'; + break; + case UPLOAD_ERR_NO_FILE: + echo $i18n['no_file'].'
'; + break; + } + } else { + $basename = basename($_FILES['mod_archive']['name']); + // Check future radio buttons + // for now, try auto-detect + $compression = null; + $ext = ''; + if (substr($basename,-4,4) == '.tar') { + $compression = null; + $ext = '.tar'; + } else if (substr($basename,-7,7) == '.tar.gz') { + $compression = 'gz'; + $ext = '.tar.gz'; + } else if (substr($basename,-4,4) == '.tgz') { + $compression = 'gz'; + $ext = '.tgz'; + } else if (substr($basename,-8,8) == '.tar.bz2') { + $compression = 'bz2'; + $ext = '.tar.bz2'; + } else if (substr($basename,-4,4) == '.zip') { + $compression = 'zip'; + $ext = '.zip'; + } + + if ($ext == '') { + echo $i18n['bad_archive'].'
'; + } else { + if (!defined('SYS_FILES')) require_once(BASE.'subsystems/files.php'); + + // Look for stale sessid directories: + $sessid = session_id(); + if (file_exists(BASE."extensionuploads/$sessid") && is_dir(BASE."extensionuploads/$sessid")) exponent_files_removeDirectory("extensionuploads/$sessid"); + $return = exponent_files_makeDirectory("extensionuploads/$sessid"); + if ($return != SYS_FILES_SUCCESS) { + switch ($return) { + case SYS_FILES_FOUNDFILE: + case SYS_FILES_FOUNDDIR: + echo $i18n['file_in_parh'].'
'; + break; + case SYS_FILES_NOTWRITABLE: + echo $i18n['dest_not_w'].'
'; + break; + case SYS_FILES_NOTREADABLE: + echo $i18n['dest_not_r'].'
'; + break; + } + } + + $dest = BASE."extensionuploads/$sessid/archive$ext"; + move_uploaded_file($_FILES['mod_archive']['tmp_name'],$dest); + + if ($compression != 'zip') {// If not zip, must be tar + include_once(BASE.'external/Tar.php'); + + $tar = new Archive_Tar($dest,$compression); + + PEAR::setErrorHandling(PEAR_ERROR_PRINT); + $return = $tar->extract(dirname($dest)); + if (!$return) { + echo '
'.$i18n['error_tar'].'
'; + } else { + header('Location: ' . URL_FULL . 'index.php?module=administrationmodule&action=verify_extension&type=tar'); + } + } else { // must be zip + include_once(BASE.'external/Zip.php'); + + $zip = new Archive_Zip($dest); + + PEAR::setErrorHandling(PEAR_ERROR_PRINT); + if ($zip->extract(array('add_path'=>dirname($dest))) == 0) { + echo '
'.$i18n['error_zip'].':
'; + echo $zip->_error_code . ' : ' . $zip->_error_string . '
'; + } else { + header('Location: ' . URL_FULL . 'index.php?module=administrationmodule&action=verify_extension&type=zip'); + } + } + } + } + } + public function manage_themes() { expHistory::set('managable', $this->params); $themes = array(); diff --git a/framework/modules/administration/menus/admin.php b/framework/modules/administration/menus/admin.php index bf0197bd7d..165f966b94 100755 --- a/framework/modules/administration/menus/admin.php +++ b/framework/modules/administration/menus/admin.php @@ -83,7 +83,7 @@ 'itemdata'=>array( array( 'classname' => 'moreinfo', - 'text'=>"Exponent Version : ".$my_version."
Release level : ".$my_type."
Release date : ".date("F-d-Y",EXPONENT_VERSION_BUILDDATE)."
PHP Version : ".phpversion(),"disabled"=>true + 'text'=>"Exponent Version : ".$my_version."
Release level : ".$my_type."
Release date : ".date("F-d-Y",EXPONENT_VERSION_BUILDDATE),"disabled"=>true ) ) ) @@ -184,17 +184,9 @@ array( 'text' => (DEVELOPMENT)?expLang::gettext('Turn Error Reporting off'):expLang::gettext('Turn Error Reporting on'), 'classname' => (DEVELOPMENT)?'develop_on_red':'develop_off', - 'url' => makeLink(array( - 'module' => 'administrationmodule', - 'action' => 'toggle_dev' - )) - ), - array( - 'text' => (MINIFY)?expLang::gettext('Turn Minification off'):expLang::gettext('Turn Minification on'), - 'classname' => (MINIFY)?'develop_on_green':'develop_off', 'url' => makeLink(array( 'module' => 'administration', - 'action' => 'toggle_minify' + 'action' => 'toggle_dev' )) ), array( @@ -205,8 +197,8 @@ array( 'text' => $i18n['install_tables'], 'url' => makeLink(array( - 'module' => 'administrationmodule', - 'action' => 'installtables' + 'module' => 'administration', + 'action' => 'install_tables' )) ), // array( @@ -224,8 +216,22 @@ array( 'text' => $i18n['optimize_database'], 'url' => makeLink(array( - 'module' => 'administrationmodule', - 'action' => 'optimizedatabase' + 'module' => 'administration', + 'action' => 'optimize_database' + )) + ), + array( + 'text' => 'Repair Database', + 'url' => makeLink(array( + 'module' => 'administration', + 'action' => 'fix_database' + )) + ), + array( + 'text' => 'Reset Sessions Table', + 'url' => makeLink(array( + 'module' => 'administration', + 'action' => 'fix_sessions' )) ), array( @@ -292,7 +298,7 @@ 'text' => $i18n['upload_extension'], 'classname'=>'fileuploader', 'url' => makeLink(array( - 'module' => 'administrationmodule', + 'module' => 'administration', 'action' => 'upload_extension' )) ), @@ -316,19 +322,67 @@ ) ), array( - 'text' => $i18n['clear_smarty'], - 'classname' => 'remove', - 'url' => makeLink(array( - 'module' => 'administrationmodule', - 'action' => 'clear_smarty_cache' - )) - ), + 'text' => expLang::gettext('System Cache'), + 'submenu' => array( + 'id' => 'cache', + 'itemdata' => array( + array( + 'text' => (MINIFY)?expLang::gettext('Turn Minification off'):expLang::gettext('Turn Minification on'), + 'classname' => (MINIFY)?'develop_on_green':'develop_off', + 'url' => makeLink(array( + 'module' => 'administration', + 'action' => 'toggle_minify' + )) + ), + array( + 'text' => $i18n['clear_smarty'], + 'classname' => 'remove', + 'url' => makeLink(array( + 'module' => 'administration', + 'action' => 'clear_smarty_cache' + )) + ), + array( + 'text' => expLang::gettext('Clear CSS/Minify Cache'), + 'classname' => 'remove', + 'url' => makeLink(array( + 'module' => 'administration', + 'action' => 'clear_css_cache' + )) + ), + array( + 'text' => expLang::gettext('Clear Image Cache'), + 'classname' => 'remove', + 'url' => makeLink(array( + 'module' => 'administration', + 'action' => 'clear_image_cache' + )) + ), + array( + 'text' => expLang::gettext('Clear RSS/Podcast Cache'), + 'classname' => 'remove', + 'url' => makeLink(array( + 'module' => 'administration', + 'action' => 'clear_rss_cache' + )) + ), + array( + 'text' => expLang::gettext('Clear All Caches'), + 'classname' => 'remove', + 'url' => makeLink(array( + 'module' => 'administration', + 'action' => 'clear_all_caches' + )) + ), + ) + ) + ), array( 'text' => (MAINTENANCE_MODE)?expLang::gettext('Turn Maintenance Mode off'):expLang::gettext('Turn Maintenance Mode on'), 'classname' => (MAINTENANCE_MODE)?'develop_on_red':'develop_off', 'text' => $i18n['toggle_maint'], 'url' => makeLink(array( - 'module' => 'administrationmodule', + 'module' => 'administration', 'action' => 'toggle_maintenance' )) ) diff --git a/framework/modules/administration/views/administration/install_tables.tpl b/framework/modules/administration/views/administration/install_tables.tpl new file mode 100644 index 0000000000..3779724e5a --- /dev/null +++ b/framework/modules/administration/views/administration/install_tables.tpl @@ -0,0 +1,66 @@ +{* + * Copyright (c) 2004-2011 OIC Group, Inc. + * Written and Designed by James Hunt + * + * This file is part of Exponent + * + * Exponent 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. + * + * GPL: http://www.gnu.org/licenses/gpl.txt + * + *} + +{css unique="install-tables" corecss="tables"} + +{/css} + +
+

Installing and Upgrading Database Tables

+

+ {$_TR.form_header} +

+
+ + + + + + + + + {foreach from=$status key=table item=statusnum} + + + + + {/foreach} + +
Table NameStatus
+ {$table} + + {if $statusnum == $smarty.const.TMP_TABLE_EXISTED} +
+ Exists +
+ {elseif $statusnum == $smarty.const.TMP_TABLE_INSTALLED} +
+ Succeeded +
+ {elseif $statusnum == $smarty.const.TMP_TABLE_FAILED} +
+ Failed +
+ {elseif $statusnum == $smarty.const.TMP_TABLE_ALTERED} +
+ Altered Existing +
+ {elseif $statusnum == $smarty.const.TABLE_ALTER_FAILED} +
+ Altering Failed +
+ {/if} +
\ No newline at end of file diff --git a/framework/modules/administration/views/administration/manage_unused_tables.tpl b/framework/modules/administration/views/administration/manage_unused_tables.tpl index 7b81f0cb07..d992fa65e8 100755 --- a/framework/modules/administration/views/administration/manage_unused_tables.tpl +++ b/framework/modules/administration/views/administration/manage_unused_tables.tpl @@ -22,7 +22,7 @@

Deprecated/Unused Tables

{$unused_tables|@count} unused tables found

- The list of tables below are ones that are no long used by Exponent. These tables probably + The list of tables below are ones that are no longer used by Exponent. These tables probably aren't hurting anything. If you do not have a good idea of what a table does or why it is there it is probably best to just leave it.

diff --git a/framework/modules/administration/views/administration/optimize_database.tpl b/framework/modules/administration/views/administration/optimize_database.tpl new file mode 100644 index 0000000000..3e60cf493a --- /dev/null +++ b/framework/modules/administration/views/administration/optimize_database.tpl @@ -0,0 +1,37 @@ +{* + * Copyright (c) 2004-2011 OIC Group, Inc. + * Written and Designed by James Hunt + * + * This file is part of Exponent + * + * Exponent 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. + * + * GPL: http://www.gnu.org/licenses/gpl.txt + * + *} + +{css unique="optimize-database" corecss="tables"} + +{/css} + +

Optimized the Database Tables

+ + + + + + + + + {foreach from=$before key=table item=info} + + + + + {/foreach} + +
Table NameSize of Data (kb)
{$table}{math format="%.3f" equation="x / 1024" x=$info->data_total} {$_TR.kb}
\ No newline at end of file diff --git a/framework/modules/administration/views/administration/upload_extension.tpl b/framework/modules/administration/views/administration/upload_extension.tpl new file mode 100644 index 0000000000..41f07584f6 --- /dev/null +++ b/framework/modules/administration/views/administration/upload_extension.tpl @@ -0,0 +1,24 @@ +{* + * Copyright (c) 2004-2011 OIC Group, Inc. + * Written and Designed by James Hunt + * + * This file is part of Exponent + * + * Exponent 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. + * + * GPL: http://www.gnu.org/licenses/gpl.txt + * + *} + +
+ +

Upload new Extension

+
+

This form allows you to upload modules, themes, plugins, and views to the website. After you upload an archive containing an extension (or more) you will be shown a pre-installation summary page, outlining exactly what files will be installed where, and what each file contains (for security reasons).

+{$form_html} \ No newline at end of file diff --git a/install/upgrades/clear_cache.php b/install/upgrades/clear_cache.php index fc365d3a31..b1433f2793 100644 --- a/install/upgrades/clear_cache.php +++ b/install/upgrades/clear_cache.php @@ -48,7 +48,6 @@ function upgrade() { // work our way through all the tmp files and remove them if (!defined('SYS_FILES')) include_once(BASE.'subsystems/files.php'); $files = array( - BASE.'tmp/cache', // not used?? FIXME BASE.'tmp/mail', // not used?? FIXME BASE.'tmp/pods', // not used?? FIXME BASE.'tmp/css', // exponent minified css cache @@ -56,6 +55,7 @@ function upgrade() { BASE.'tmp/pixidou', // (new) pixidou cache BASE.'tmp/rsscache', // magpierss cache BASE.'tmp/views_c', // smarty cache + BASE.'tmp/cache', // alternate smarty cache ); // delete the files. @@ -68,7 +68,8 @@ function upgrade() { } // phpThumb cache includes subfolders - if (file_exists(BASE.'tmp/img_cache')) $this->cleardir_recursive(BASE.'tmp/img_cache'); +// if (file_exists(BASE.'tmp/img_cache')) $this->cleardir_recursive(BASE.'tmp/img_cache'); + if (file_exists(BASE.'tmp/img_cache')) exponent_files_remove_files_in_directory(BASE.'tmp/img_cache'); return "Caches were cleared.
".$errors." files could not be removed."; } diff --git a/install/upgrades/fix_database.php b/install/upgrades/fix_database.php index 83cbe7f69e..8a75e26f65 100644 --- a/install/upgrades/fix_database.php +++ b/install/upgrades/fix_database.php @@ -53,11 +53,17 @@ function needed() { function upgrade() { global $db; + print_r("
");
+	    print_r("

Some Error Conditions can NOT be repaired by this Procedure!


"); print_r("
");
 	// upgrade sectionref's that have lost their originals
 		print_r("Searching for sectionrefs that have lost their originals

"); $sectionrefs = $db->selectObjects('sectionref',"is_original=0"); - print_r("Found: ".count($sectionrefs)." copies (not originals)
"); + if (count($sectionrefs)) { + print_r("Found: ".count($sectionrefs)." copies (not originals)
"); + } else { + print_r("None Found: Good!
"); + } foreach ($sectionrefs as $sectionref) { if ($db->selectObject('sectionref',"module='".$sectionref->module."' AND source='".$sectionref->source."' AND is_original='1'") == null) { // There is no original for this sectionref so change it to the original @@ -72,14 +78,19 @@ function upgrade() { // upgrade sectionref's that point to missing sections (pages) print_r("Searching for sectionrefs pointing to missing sections/pages
to fix for the Recycle Bin


"); $sectionrefs = $db->selectObjects('sectionref',"refcount!=0"); + $found = 0; foreach ($sectionrefs as $sectionref) { if ($db->selectObject('section',"id='".$sectionref->section."'") == null) { // There is no section/page for sectionref so change the refcount $sectionref->refcount = 0; $db->updateObject($sectionref,"sectionref"); print_r("Fixed: ".$sectionref->module." - ".$sectionref->source."
"); + $found += 1; } } + if (!$found) { + print_r("None Found: Good!
"); + } print_r("
"); // FIXME Not needed when locationrefs are removed @@ -95,7 +106,7 @@ function upgrade() { $newLocRef->source = $sectionref->source; $newLocRef->internal = $sectionref->internal; $newLocRef->refcount = $sectionref->refcount; - $db->insertObject($newLocRef,"locationref"); + $db->insertObject($newLocRef,'locationref'); print_r("Copied: ".$sectionref->module." - ".$sectionref->source."
"); } } @@ -104,16 +115,20 @@ function upgrade() { print_r("
");
 	 // delete sectionref's & locationref's that have empty sources since they are dead
 		 print_r("Searching for unassigned modules (no source)

"); - $sectionrefs = $db->selectObjects('sectionref',"source=''"); + $sectionrefs = $db->selectObjects('sectionref','source=""'); if ($sectionrefs != null) { - print_r("Removing: ".count($sectionrefs)." sectionref empties (no source)
"); - $db->delete('sectionref',"source=''"); + print_r("Removing: ".count($sectionrefs)." empty sectionref's (no source)
"); + $db->delete('sectionref','source=""'); + } else { + print_r("No Empties Found: Good!
"); } // FIXME Not needed when locationrefs are removed - $locationrefs = $db->selectObjects('locationref',"source=''"); + $locationrefs = $db->selectObjects('locationref','source=""'); if ($locationrefs != null) { - print_r("Removing: ".count($locationrefs)." locationref empties (no source)
"); - $db->delete('locationref',"source=''"); + print_r("Removing: ".count($locationrefs)." empty locationref's (no source)
"); + $db->delete('locationref','source=""'); + } else { + print_r("No Empties Found: Good!
"); } print_r("
"); diff --git a/install/upgrades/install_tables.php b/install/upgrades/install_tables.php index 1bbef014ab..29b3787ba6 100644 --- a/install/upgrades/install_tables.php +++ b/install/upgrades/install_tables.php @@ -163,7 +163,7 @@ function upgrade() {
- +
@@ -185,10 +185,12 @@ function upgrade() { $line++; } ?> - - + + + No Tables Were Changed!

"; } diff --git a/subsystems/files.php b/subsystems/files.php index 07c3459503..e02a29ab0e 100755 --- a/subsystems/files.php +++ b/subsystems/files.php @@ -88,12 +88,14 @@ function exponent_files_makeDirectory($dir,$mode=null,$is_full=false) { return SYS_FILES_SUCCESS; } -/* exdoc +/** * Recursively removes the given directory, and all * of the files and directories underneath it. * * @param string $dir The path of the directory to remove * @node Subsystems:Files + * @param string $dir directory to work with + * @return int */ function exponent_files_removeDirectory($dir) { if (strpos($dir,BASE) != 0) $dir = BASE.$dir; @@ -285,11 +287,40 @@ function exponent_files_canCreate($dest) { } } -// FIXME doesn't always recurse -function exponent_files_remove_files_in_directory($dir) { - $files['removed'] = array(); - $files['not_removed'] = array(); +/** + * Recursively removes all files in a given directory, and all + * the files and directories underneath it. + * Optionally can skip dotfiles + * + * @param string $dir directory to work with + * @param bool $dot_files should dotfiles be removed? + * @return array + */ +function exponent_files_remove_files_in_directory($dir, $dot_files = false) { + $results['removed'] = array(); + $results['not_removed'] = array(); + $files = scandir($dir); + array_shift($files); // remove '.' from array + array_shift($files); // remove '..' from array + foreach ($files as $file) { + if ($dot_files || substr($file, 0, 1) != '.') { // don't remove dot files + $file = $dir . '/' . $file; + if (is_dir($file)) { + cleardir_recursive($file); + rmdir($file); + } else { + if (is_writeable($file) && !is_dir($file)) { + unlink($file); + $results['removed'][] = $file; + } else { + $results['not_removed'][] = $file; + } + } + } + } + +/* odl routine if (is_readable($dir)) { $dh = opendir($dir); while (($file = readdir($dh)) !== false) { @@ -297,15 +328,15 @@ function exponent_files_remove_files_in_directory($dir) { if (substr($file,0,1) != '.') { if (is_writeable($filepath) && !is_dir($filepath)) { unlink($filepath); - $files['removed'][] = $filepath; + $results['removed'][] = $filepath; } else { - $files['not_removed'][] = $filepath; + $results['not_removed'][] = $filepath; } } } - } + }*/ - return $files; + return $results; } function exponent_files_bytesToHumanReadable($size) {