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("
"); + // upgrade sectionref's that have lost their originals + print_r("Searching for sectionrefs that have lost their originals"); + + print_r("
"); + $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("
"); + // upgrade sectionref's that point to missing sections (pages) + print_r("Searching for sectionrefs pointing to missing sections/pages"); + +// FIXME Not needed when locationrefs are removed + print_r("
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("
"); + // add missing locationref's based on existing sectionref's + print_r("Searching for detached modules with no original (no matching locationref)"); + + print_r("
"); + $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("
"); + // delete sectionref's & locationref's that have empty sources since they are dead + print_r("Searching for unassigned modules (no source)"); + + print_r("
"); + $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("
"); + // add missing sectionrefs based on existing containers (fixes aggregation problem) + print_r("Searching for missing sectionref's based on existing container's"); + } + 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'].'
"); + $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("
+ {$_TR.form_header} +
+Table Name | +Status | +
---|---|
+ {$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}
+ |
+
- 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} + +Table Name | +Size of Data (kb) | +
---|---|
{$table} | +{math format="%.3f" equation="x / 1024" x=$info->data_total} {$_TR.kb} | +
"); + 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"); // 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."
"); $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("
"); } } @@ -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)"); 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() {
"); - $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("- +@@ -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) {