private static function _apply_indexes($schema_name, $schema_fields) { $buffer = array(); if (($indexes = self::table_get_indexes($schema_name)) === false) { $buffer[] = sprintf("{t}SQL FAILED: %s{/t}\n", "table_get_indexes") . sql_error(); } $primaries = array(); foreach ($schema_fields as $field) { if (isset($field["INDEX"]) and (!isset($indexes[$field["NAME"]]) or !$indexes[$field["NAME"]]["index"])) { if (!self::table_add_index("", "ind_" . str_replace(array("simple_"), "", $schema_name) . "_" . $field["NAME"], $schema_name, $field["NAME"])) { $buffer[] = sprintf("{t}SQL FAILED: %s{/t}\n", "table_add_index - " . $schema_name . " - " . $field["NAME"]) . sql_error(); } } if (isset($field["INDEX_FULLTEXT"]) and (!isset($indexes[$field["NAME"]]) or !$indexes[$field["NAME"]]["index"])) { if (!self::table_add_index("FULLTEXT", "ind_" . str_replace("simple_", "", $schema_name) . "_" . $field["NAME"], $schema_name, $field["NAME"])) { $buffer[] = sprintf("{t}SQL FAILED: %s{/t}\n", "table_add_index_fulltext") . sql_error(); } } if (isset($field["KEY"])) { $primaries[] = $field["NAME"]; } } if (count($primaries) > 0) { $change = false; foreach ($primaries as $primary) { if (!isset($indexes[$primary]) or !$indexes[$primary]["primary"]) { $change = true; } } if ($change) { self::table_drop_index($schema_name, "PRIMARY KEY"); if (!self::table_change_primary_key($schema_name, implode(",", $primaries))) { $buffer[] = sprintf("{t}SQL FAILED: %s{/t}\n", "table_change_primary_key") . sql_error(); } } } if (!sql_table_optimize($schema_name)) { $buffer[] = sprintf("{t}SQL FAILED: %s{/t}\n", "sql_table_optimize") . sql_error(); } return $buffer; }
static function process_action_sys() { @set_time_limit(900); switch ($_REQUEST["action_sys"]) { case "maintenance": if (!sys_validate_token()) { sys_die("{t}Invalid security token{/t}"); } $lock_file = SIMPLE_STORE . "/maintenance.lck"; if (!file_exists($lock_file)) { touch($lock_file); sys_log_message_alert("info", "{t}Maintenance mode{/t}: {t}Active{/t}"); } else { unlink($lock_file); sys_log_message_alert("info", "{t}Maintenance mode{/t}: {t}Inactive{/t}"); } break; case "clear_locking": self::_remove_locks(); dirs_create_empty_dir(SIMPLE_STORE . "/locking"); sys_log_message_log("clean", "{t}Locking{/t}"); break; case "clear_output": dirs_create_empty_dir(SIMPLE_CACHE . "/smarty"); dirs_create_empty_dir(SIMPLE_CACHE . "/output"); dirs_create_empty_dir(SIMPLE_CACHE . "/artichow"); dirs_create_empty_dir(SIMPLE_CACHE . "/thumbs"); dirs_create_empty_dir(SIMPLE_CACHE . "/lang"); self::build_css(); self::build_js(); self::build_icons(); sys_log_message_log("clean", "{t}Output{/t}"); break; case "clear_debug": dirs_create_empty_dir(SIMPLE_CACHE . "/debug"); sys_log_message_log("clean", "{t}Debug-dir{/t}"); break; case "clear_cms": dirs_create_empty_dir(SIMPLE_CACHE . "/cms"); sys_log_message_log("clean", "{t}CMS{/t}"); break; case "clear_ip": dirs_create_empty_dir(SIMPLE_CACHE . "/ip"); if (APC) { apc_clear_cache("user"); } sys_log_message_log("clean", "IP"); break; case "clear_schema": dirs_create_empty_dir(SIMPLE_CACHE . "/schema"); if (APC) { apc_clear_cache("user"); } sys_log_message_log("clean", "{t}Schema{/t}"); break; case "clear_schemadata": dirs_create_empty_dir(SIMPLE_CACHE . "/schema_data"); dirs_create_empty_dir(SIMPLE_CACHE . "/preview"); if (APC) { apc_clear_cache("user"); } sys_log_message_log("clean", "{t}Schema data{/t}"); break; case "clear_email": dirs_create_empty_dir(SIMPLE_CACHE . "/imap"); dirs_create_empty_dir(SIMPLE_CACHE . "/pop3"); sys_log_message_log("clean", "{t}E-mail{/t}"); break; case "clean_notifications": db_delete("simple_sys_notifications", array("sent='1'"), array()); sql_table_optimize("simple_sys_notifications"); sys_log_message_log("clean", "{t}Notifications{/t}"); break; case "clear_upload": dirs_create_empty_dir(SIMPLE_CACHE . "/upload"); sys_log_message_log("clean", "{t}Uploaded files{/t}"); break; case "clean_tables": db_optimize_tables(); sys_log_message_log("clean", "{t}Optimize Tables{/t}"); break; case "clean_statistics": if (!sys_validate_token()) { sys_die("{t}Invalid security token{/t}"); } db_delete("simple_sys_stats", array(), array()); sql_table_optimize("simple_sys_stats"); sys_log_message_log("clean", "{t}Statistics{/t}"); break; case "clean_events": if (!sys_validate_token()) { sys_die("{t}Invalid security token{/t}"); } db_delete("simple_sys_events", array(), array()); $folder = db_select_value("simple_sys_tree", "id", "ftype=@type@", array("type" => "sys_events")); if (!empty($folder)) { db_delete("simple_sys_search", array("folder=@folder@"), array("folder" => $folder)); } sql_table_optimize("simple_sys_events"); sql_table_optimize("simple_sys_search"); sys_log_message_log("clean", "{t}Events{/t}"); break; case "clean_trash": if (!sys_validate_token()) { sys_die("{t}Invalid security token{/t}"); } $trash = db_select_value("simple_sys_tree", "id", "anchor=@anchor@", array("anchor" => "trash")); if (!empty($trash)) { $folders = db_select("simple_sys_tree", array("id", "fmountpoint"), "parent=@parent@", "", "", array("parent" => $trash)); if (is_array($folders) and count($folders) > 0) { foreach ($folders as $folder) { if (!empty($folder["fmountpoint"])) { continue; } folders::delete($folder["id"]); } } } dirs_create_empty_dir(SIMPLE_STORE . "/trash"); sys_log_message_log("clean", "{t}Trash{/t}"); sys_redirect("index.php?" . sys::$urladdon); break; case "clean_cache": $dirs = array(SIMPLE_STORE . "/cron", SIMPLE_CACHE . "/imap", SIMPLE_CACHE . "/pop3", SIMPLE_CACHE . "/smarty", SIMPLE_CACHE . "/cms", SIMPLE_CACHE . "/cifs", SIMPLE_CACHE . "/gdocs", SIMPLE_CACHE . "/lang", SIMPLE_CACHE . "/output", SIMPLE_CACHE . "/artichow", SIMPLE_CACHE . "/thumbs", SIMPLE_CACHE . "/schema"); foreach ($dirs as $dir) { self::_dirs_clean_dir($dir, 2592000); } // 30 days self::_remove_locks(); $dirs = array(SIMPLE_CACHE . "/schema_data", SIMPLE_CACHE . "/preview", SIMPLE_STORE . "/locking", SIMPLE_CACHE . "/upload", SIMPLE_CACHE . "/ip", SIMPLE_CACHE . "/debug", SIMPLE_CACHE . "/updater", SIMPLE_CACHE . "/backup"); foreach ($dirs as $dir) { self::_dirs_clean_dir($dir, 86400); } // 1 day sys_log_message_log("clean", "{t}Clean Cache{/t}"); sys_redirect("index.php?" . sys::$urladdon); break; case "clear_setup": if (!sys_validate_token()) { sys_die("{t}Invalid security token{/t}"); } @unlink("simple_store/config.php"); @unlink("simple_store/config_old.php"); header("Location: index.php"); exit; break; case "backup": self::_create_backup($_SESSION["folder"]); self::_out("<br><a href='index.php?folder=^system/!sys_nodb_backups'>{t}Continue{/t}</a>"); exit; break; case "restore_newer": self::$_restore_onlynewer = true; echo self::_restore($_REQUEST["file"]); self::_out("<br><a href='index.php'>{t}Continue{/t}</a>"); exit; break; case "restore": echo self::_restore($_REQUEST["file"]); self::_out("<br><a href='index.php'>{t}Continue{/t}</a>"); exit; break; case "restore_here": self::$_restore_here = true; echo self::_restore($_REQUEST["file"]); self::_out("<br><a href='index.php'>{t}Continue{/t}</a>"); exit; break; case "restore_missing": self::$_restore_missing = true; echo self::_restore($_REQUEST["file"]); self::_out("<br><a href='index.php'>{t}Continue{/t}</a>"); exit; break; case "rebuild_search": if (!sys_validate_token()) { sys_die("{t}Invalid security token{/t}"); } self::rebuild_schema(true); self::_out("<br><a href='index.php'>{t}Continue{/t}</a>"); exit; break; case "clear_session": if (!sys_validate_token()) { sys_die("{t}Invalid security token{/t}"); } db_delete("simple_sys_session", array(), array()); if (APC) { apc_clear_cache("user"); } sys_log_message_log("clean", "{t}Sessions{/t}"); self::_out("<br><a href='index.php'>{t}Continue{/t}</a>"); exit; break; case "phpinfo": echo "System time: " . date("c") . "<br>"; echo "Database time: " . sgsml_parser::sql_date(); phpinfo(); exit; break; } }
function db_optimize_tables() { if (!sql_table_optimize()) { sys_log_message_log("db-fail", "optimize " . sql_error()); } }