dumpTable() public method

Dumps table to logical file.
public dumpTable ( $handle, $table ) : void
return void
示例#1
0
 /**
  * 
  * @param \KEvent $event
  */
 public function onAfterSchemaMigration(\KEvent $event)
 {
     if ($event->caller->getComponent() == 'anahita') {
         $path = ANAHITA_ROOT . '/vendor/joomla/installation/sql';
         $event->caller->setOutputPath($path);
     }
     $tables = $event->caller->getTables();
     $schema_file = $event->caller->getOutputPath() . '/schema.sql';
     $uninstall_file = $event->caller->getOutputPath() . '/uninstall.sql';
     $schema = fopen($schema_file, 'w');
     $uninstall = fopen($uninstall_file, 'w');
     $dump = new \MySQLDump($event->caller->getDatabaseAdapter()->getConnection());
     $prefix_replace = array();
     foreach ($tables as $table) {
         $prefix_replace[$table] = str_replace($event->caller->getDatabaseAdapter()->getTablePrefix(), '#__', $table);
         $dump->tables[$table] = \MySQLDump::CREATE;
         $dump->dumpTable($schema, $table);
         $dump->tables[$table] = \MySQLDump::DROP;
         $dump->dumpTable($uninstall, $table);
     }
     $version = $event->caller->getCurrentVersion();
     $component = $event->caller->getComponent();
     fwrite($schema, "INSERT INTO #__migrator_versions (`version`,`component`) " . "VALUES({$version}, '{$component}') ON DUPLICATE KEY UPDATE `version` = {$version};");
     fwrite($uninstall, "DELETE #__migrator_versions  WHERE `component` = '{$component}';");
     fclose($schema);
     fclose($uninstall);
     //fix the prefix
     foreach (array($schema_file, $uninstall_file) as $file) {
         $content = file_get_contents($file);
         $content = str_replace(array_keys($prefix_replace), array_values($prefix_replace), $content);
         file_put_contents($file, $content);
     }
     $content = file_get_contents($schema_file);
     $replace = array('/ TYPE=/' => ' ENGINE=', '/ AUTO_INCREMENT=\\w+/' => '');
     //fix the auto increment
     $content = preg_replace(array_keys($replace), array_values($replace), file_get_contents($schema_file));
     file_put_contents($schema_file, $content);
     //delete uninsall file for anahita
     if ($event->caller->getComponent() == 'anahita') {
         unlink($uninstall_file);
     }
 }