1 <?php
 2 
 3 /**
 4  * Cronjob Addon - Plugin optimize_tables.
 5  *
 6  * @author gharlan[at]web[dot]de Gregor Harlan
 7  *
 8  * @package redaxo\cronjob\optimize-tables
 9  */
10 
11 class rex_cronjob_optimize_tables extends rex_cronjob
12 {
13     public function execute()
14     {
15         $tables = rex_sql::factory()->getTables(rex::getTablePrefix());
16         if (is_array($tables) && !empty($tables)) {
17             $sql = rex_sql::factory();
18             // $sql->setDebug();
19             try {
20                 $sql->setQuery('OPTIMIZE TABLE ' . implode(', ', $tables));
21                 return true;
22             } catch (rex_sql_exception $e) {
23                 return false;
24             }
25         }
26         return false;
27     }
28 
29     public function getTypeName()
30     {
31         return rex_i18n::msg('cronjob_optimize_tables');
32     }
33 }
34