}
//Optimize tables that are not part of the browse definition
SwitchDatabase::switchToVuFind();
set_time_limit(300);
optimizeTable('title_browse');
optimizeTable('title_browse_metadata');
optimizeTable('title_browse_scoped_results_global');
optimizeTable('author_browse');
optimizeTable('author_browse_metadata');
optimizeTable('author_browse_scoped_results_global');
optimizeTable('subject_browse');
optimizeTable('subject_browse_metadata');
optimizeTable('subject_browse_scoped_results_global');
optimizeTable('callnumber_browse');
optimizeTable('callnumber_browse_metadata');
optimizeTable('callnumber_browse_scoped_results_global');
while ($library->fetch()) {
    optimizeTable("title_browse_scoped_results_library_{$library->subdomain}");
    optimizeTable("author_browse_scoped_results_library_{$library->subdomain}");
    optimizeTable("subject_browse_scoped_results_library_{$library->subdomain}");
    optimizeTable("callnumber_browse_scoped_results_library_{$library->subdomain}");
}
$logger->log('Finished optimizing tables', PEAR_LOG_INFO);
function optimizeTable($tableName)
{
    global $logger;
    set_time_limit(1000);
    echo "Optimizing {$tableName}<br/>\r\n";
    mysql_query("OPTIMIZE TABLE {$tableName};");
    $logger->log('Optimized table: ' . $tableName, PEAR_LOG_INFO);
}
Esempio n. 2
0
function parseTextArea($table)
{
    // make outside variables accessible within the function scope
    global $id, $db_link;
    // Get number of existing (old) rows so we know how many to remove later.
    global $numOldRows;
    $numOldRows = mysql_num_rows(mysql_query("SELECT * FROM {$table} WHERE ID={$id}", $db_link));
    // trim any whitespace characters from the beginning and end of the textarea string
    // this removes, for instance, any extra newline characters at the end of the string
    $txtarea = trim($_POST[$table]);
    // if textarea is empty and there are no old rows, then exit the function
    if (!$txtarea && $numOldRows == 0) {
        return 0;
    }
    // if textarea is empty and there *are* old rows, then there is no updates to be done. proceed to delete
    if (!$txtarea && $numOldRows > 0) {
        removeOldRows($table, $numOldRows);
        return 1;
    }
    // Splits textarea lines into an array.
    $newEntry = explode("\n", $txtarea);
    // Obtain the number of new entries.
    $x = 0;
    while (each($newEntry)) {
        $x++;
    }
    reset($newEntry);
    // pulls the rows out of the array.
    // then splits up the rows into values which are then added to the database.
    for ($y = 0; $y < $x; $y++) {
        $newRow = "newRow" . $y;
        ${$newRow} = $newEntry[$y];
        $newRowArray = explode("|", ${$newRow});
        // turns it into another array
        /*
        // OLD
        // All textareas assume that there are 2 fields per row. One is the data itself,
        // the other is the "type" of data. Not all fields require types. E-mail, for
        // instance, often do not require one. So the second field in each row can be
        // assumed to be optional for the purposes of this script.
        // The old code allowed for any number of new values in a row, seperated by the
        // pipe character. In reality, this is useless. No rows have more or less than
        // two fields.
        // The following code is retained for future-use purposes, in case we do need
        // code that allows for variable fields per row. However, for the purposes of the
        // current script, we will use code that assumes 2 fields per row. If a second
        // field is empty, it will create blank (empty) data. If a first field is empty,
        // it will ignore the row.
        		// obtains number of values in row.
        		$z = 0;
        		while (each($newRowArray)) {
        			$z++;
        		} 
        		reset($newRowArray);
        
        		// creates initial sql command
        		$sql = "INSERT INTO $table VALUES ($id";
        
        		// now we store each seperate value of the row into variables.
        		for ($a = 0; $a < $z; $a++) {
        			$newValue = newValue . $a;
        			$$newValue = $newRowArray[$a];
        
        			// fix up the string - first strips whitespace, then strips tags, then adds slashes to the final product
        			$$newValue = addslashes( strip_tags( trim($$newValue) ) );
        
        			// concatenate this to $sql
        			$sql = $sql . ", '" . $$newValue . "'";
        
        		}
        
        		// create mysql command
        		$sql = $sql . ")";
        */
        // NEW TEXT AREA PARSE CODE
        // Turn the contents of the textarea row into something we can attach to the query
        // $newRowArray[0] = First value (required for entry)
        // $newRowArray[1] = Second value (optional)
        // $newRowArray[2,3,...] = ignored completely
        // Clean up
        $newRowArray[0] = addslashes(strip_tags(trim($newRowArray[0])));
        $newRowArray[1] = addslashes(strip_tags(trim($newRowArray[1])));
        // Insert
        if ($newRowArray[0] != "") {
            $sql = "INSERT INTO {$table} VALUES ({$id}, '{$newRowArray['0']}', '{$newRowArray['1']}')";
            runQuery($sql);
        }
    }
    // remove old entries, which should exist in the table before the new entries, and optimize
    removeOldRows($table, $numOldRows);
    optimizeTable($table);
    //end function
}
Esempio n. 3
0
 /**
  * Optimizes all tables in the database and lists how much was saved.
  *
  * What it does:
  * - It requires the admin_forum permission.
  * - It shows as the maintain_forum admin area.
  * - It is accessed from ?action=admin;area=maintain;sa=database;activity=optimize.
  * - It also updates the optimize scheduled task such that the tables are not automatically optimized again too soon.
  */
 public function action_optimize_display()
 {
     global $txt, $context;
     isAllowedTo('admin_forum');
     // Some validation
     checkSession('post');
     validateToken('admin-maint');
     ignore_user_abort(true);
     require_once SUBSDIR . '/Maintenance.subs.php';
     $context['page_title'] = $txt['database_optimize'];
     $context['sub_template'] = 'optimize';
     $tables = getElkTables();
     // If there aren't any tables then I believe that would mean the world has exploded...
     $context['num_tables'] = count($tables);
     if ($context['num_tables'] == 0) {
         fatal_error('You appear to be running ElkArte in a flat file mode... fantastic!', false);
     }
     // For each table....
     $context['optimized_tables'] = array();
     foreach ($tables as $table) {
         // Optimize the table!  We use backticks here because it might be a custom table.
         $data_freed = optimizeTable($table['table_name']);
         if ($data_freed > 0) {
             $context['optimized_tables'][] = array('name' => $table['table_name'], 'data_freed' => $data_freed);
         }
     }
     // Number of tables, etc....
     $txt['database_numb_tables'] = sprintf($txt['database_numb_tables'], $context['num_tables']);
     $context['num_tables_optimized'] = count($context['optimized_tables']);
     // Check that we don't auto optimise again too soon!
     require_once SUBSDIR . '/ScheduledTasks.subs.php';
     calculateNextTrigger('auto_optimize', true);
 }
Esempio n. 4
0
global $timer;
global $logger;
$library = new Library();
$library->find();
ob_start();
echo "<br>Starting to optimize tables<br/>\r\n";
$logger->log('Starting to optimize tables', PEAR_LOG_INFO);
ob_flush();
foreach ($configArray['Database'] as $key => $value) {
    if (preg_match('/table_(.*)/', $key, $matches)) {
        if ($value == 'vufind') {
            SwitchDatabase::switchToVuFind();
        } else {
            SwitchDatabase::switchToEcontent();
        }
        $tableName = $matches[1];
        //Some tables take too long to optimize, ignore them.
        if (!in_array($tableName, array('analytics_session', 'analytics_page_view'))) {
            optimizeTable($tableName);
        }
    }
}
$logger->log('Finished optimizing tables', PEAR_LOG_INFO);
function optimizeTable($tableName)
{
    global $logger;
    set_time_limit(1000);
    echo "Optimizing {$tableName}<br/>\r\n";
    mysql_query("OPTIMIZE TABLE {$tableName};");
    $logger->log('Optimized table: ' . $tableName, PEAR_LOG_INFO);
}