Example #1
0
/**
* Optimize database tables
*
* @param    string  $startwith  table to start with
* @param    int     $failures   number of previous errors
* @return   int                 number of errors during conversion
*
*/
function DBADMIN_dooptimize($startwith = '', $failures = 0)
{
    global $_CONF, $_TABLES;
    $retval = '';
    $start = time();
    $lasttable = DB_getItem($_TABLES['vars'], 'value', "name = 'lastoptimizedtable'");
    if (empty($startwith) && !empty($lasttable)) {
        $startwith = $lasttable;
    }
    $maxtime = @ini_get('max_execution_time');
    if (empty($maxtime)) {
        // unlimited or not allowed to query - assume 30 second default
        $maxtime = 30;
    }
    $maxtime -= 5;
    DB_displayError(true);
    $token = '';
    // SEC_createToken();
    $result = DB_query("SHOW TABLES");
    $numTables = DB_numRows($result);
    for ($i = 0; $i < $numTables; $i++) {
        $A = DB_fetchArray($result, true);
        $table = $A[0];
        if (in_array($table, $_TABLES)) {
            if (!empty($startwith)) {
                if ($table == $startwith) {
                    $startwith = '';
                } else {
                    continue;
                    // already handled - skip
                }
                if (!empty($lasttable) && $lasttable == $table) {
                    continue;
                    // skip
                }
            }
            if (time() > $start + $maxtime) {
                // this is taking too long - kick off another request
                $startwith = $table;
                $url = $_CONF['site_admin_url'] . '/database.php?dooptimize=x';
                if (!empty($token)) {
                    $token = '&' . CSRF_TOKEN . '=' . $token;
                }
                header("Location: {$url}&startwith={$startwith}&failures={$failures}" . $token);
                exit;
            }
            if (empty($lasttable)) {
                DB_query("INSERT INTO {$_TABLES['vars']} (name, value) VALUES ('lastoptimizedtable', '{$table}')");
                $lasttable = $table;
            } else {
                DB_query("UPDATE {$_TABLES['vars']} SET value = '{$table}' WHERE name = 'lastoptimizedtable'");
            }
            $optimize = DB_query("OPTIMIZE TABLE {$table}", 1);
            if ($optimize === false) {
                $failures++;
                COM_errorLog('SQL error for table "' . $table . '" (ignored): ' . DB_error());
                $startwith = $table;
                $url = $_CONF['site_admin_url'] . '/database.php?dooptimize=x';
                if (!empty($token)) {
                    $token = '&' . CSRF_TOKEN . '=' . $token;
                }
                header("Location: {$url}&startwith={$startwith}&failures={$failures}" . $token);
                exit;
            }
        }
    }
    DB_delete($_TABLES['vars'], 'name', 'lastoptimizedtable');
    DB_delete($_TABLES['vars'], 'name', 'lastoptimizeddb');
    DB_query("INSERT INTO {$_TABLES['vars']} (name, value) VALUES ('lastoptimizeddb', FROM_UNIXTIME(" . time() . "))");
    return $failures;
}
Example #2
0
// +---------------------------------------------------------------------------+
// | DO NOT TOUCH ANYTHING BELOW HERE                                          |
// +---------------------------------------------------------------------------+
/**
* Include appropriate DBMS object
*
*/
if ($_DB_dbms === 'mysql' and class_exists('MySQLi')) {
    require_once $_CONF['path_system'] . 'databases/mysqli.class.php';
} else {
    require_once $_CONF['path_system'] . 'databases/' . $_DB_dbms . '.class.php';
}
// Instantiate the database object
$_DB = new database($_DB_host, $_DB_name, $_DB_user, $_DB_pass, 'COM_errorLog', $_CONF['default_charset']);
if (isset($_CONF['rootdebug']) && $_CONF['rootdebug']) {
    DB_displayError(true);
}
// +---------------------------------------------------------------------------+
// | These are the library functions.  In all cases they turn around and make  |
// | calls to the DBMS specific functions.  These ARE to be used directly in   |
// | the code...do NOT use the $_DB methods directly                           |
// +---------------------------------------------------------------------------+
/**
* Turns debug mode on for the database library
*
* Setting this to true will cause the database code to print out
* various debug messages.  Setting it to false will supress the
* messages (is false by default). NOTE: Gl developers have put many
* useful debug messages into the mysql implementation of this.  If
* you are using something other than MySQL and if the GL team did
* not write it then you may or may not get something useful by turning
Example #3
0
function repairDatabase()
{
    global $rescueFields, $_TABLES, $_DB_table_prefix;
    $retval = array();
    $maxtime = @ini_get('max_execution_time');
    if (empty($maxtime)) {
        // unlimited or not allowed to query - assume 30 second default
        $maxtime = 30;
    }
    $maxtime -= 5;
    DB_displayError(true);
    $result = DB_query("SHOW TABLES");
    $numTables = DB_numRows($result);
    for ($i = 0; $i < $numTables; $i++) {
        $A = DB_fetchArray($result, true);
        $table = $A[0];
        if (in_array($table, $_TABLES)) {
            if (!empty($startwith)) {
                if ($table == $startwith) {
                    $startwith = '';
                } else {
                    continue;
                    // already handled - skip
                }
                if (!empty($lasttable) && $lasttable == $table) {
                    continue;
                    // skip
                }
            }
            $repair = DB_query("REPAIR TABLE " . $table, 1);
            if ($repair === false) {
                $retval[] = 'Repair failed for ' . $able;
            }
        }
    }
    return $retval;
}