Piwik\DbHelper::truncateAllTables PHP Method

truncateAllTables() public static method

Truncate all tables
public static truncateAllTables ( )
    public static function truncateAllTables()
    {
        Schema::getInstance()->truncateAllTables();
    }

Usage Example

Esempio n. 1
0
 /**
  * Truncates all tables then inserts the data in $tables into each
  * mapped table.
  *
  * @param array $tables Array mapping table names with arrays of row data.
  */
 protected static function restoreDbTables($tables)
 {
     // truncate existing tables
     DbHelper::truncateAllTables();
     // insert data
     $existingTables = DbHelper::getTablesInstalled();
     foreach ($tables as $table => $rows) {
         // create table if it's an archive table
         if (strpos($table, 'archive_') !== false && !in_array($table, $existingTables)) {
             $tableType = strpos($table, 'archive_numeric') !== false ? 'archive_numeric' : 'archive_blob';
             $createSql = DbHelper::getTableCreateSql($tableType);
             $createSql = str_replace(Common::prefixTable($tableType), $table, $createSql);
             Db::query($createSql);
         }
         if (empty($rows)) {
             continue;
         }
         $rowsSql = array();
         $bind = array();
         foreach ($rows as $row) {
             $values = array();
             foreach ($row as $value) {
                 if (is_null($value)) {
                     $values[] = 'NULL';
                 } else {
                     if (is_numeric($value)) {
                         $values[] = $value;
                     } else {
                         if (!ctype_print($value)) {
                             $values[] = "x'" . bin2hex(substr($value, 1)) . "'";
                         } else {
                             $values[] = "?";
                             $bind[] = $value;
                         }
                     }
                 }
             }
             $rowsSql[] = "(" . implode(',', $values) . ")";
         }
         $sql = "INSERT INTO `{$table}` VALUES " . implode(',', $rowsSql);
         Db::query($sql, $bind);
     }
 }
All Usage Examples Of Piwik\DbHelper::truncateAllTables