FOF30\Database\Installer::removeSchema PHP Method

removeSchema() public method

Uninstalls the database schema
public removeSchema ( ) : void
return void
    public function removeSchema()
    {
        // Get the schema XML file
        $xml = $this->findSchemaXml();
        if (empty($xml)) {
            return;
        }
        // Make sure there are SQL commands in this file
        if (!$xml->sql) {
            return;
        }
        // Walk the sql > action tags to find all tables
        $tables = array();
        /** @var SimpleXMLElement $actions */
        $actions = $xml->sql->children();
        /** @var SimpleXMLElement $action */
        foreach ($actions as $action) {
            $attributes = $action->attributes();
            $tables[] = (string) $attributes->table;
        }
        // Simplify the tables list
        $tables = array_unique($tables);
        // Start dropping tables
        foreach ($tables as $table) {
            try {
                $this->db->dropTable($table);
            } catch (Exception $e) {
                // Do not fail if I can't drop the table
            }
        }
    }

Usage Example

Esempio n. 1
0
 /**
  * @covers  FOF30\Database\Installer::removeSchema
  */
 public function testRemoveSchema()
 {
     $db = static::$container->db;
     $this->createTable();
     $tables = $db->setQuery('SHOW TABLES')->loadColumn();
     $prefix = $db->getPrefix();
     $this->assertTrue(in_array($prefix . 'foobar_example', $tables), 'The table must exist before testing starts');
     $installer = new Installer($db, __DIR__ . '/../_data/installer/pick_right');
     $installer->removeSchema();
     $tables = $db->setQuery('SHOW TABLES')->loadColumn();
     $prefix = $db->getPrefix();
     $this->assertFalse(in_array($prefix . 'foobar_example', $tables), 'The table must not exist after running removeSchema');
 }
All Usage Examples Of FOF30\Database\Installer::removeSchema