eZ\Bundle\EzPublishCoreBundle\Command\TestInitDbCommand::insertData PHP Метод

insertData() публичный Метод

Insert the database data.
public insertData ( string $dbType )
$dbType string Name of Database type (mysql, sqlite, pgsql, ..)
    public function insertData($dbType)
    {
        // Get Initial fixture data and union with some tables that must be present but sometimes aren't
        $data = $this->getInitialData() + array('ezcontentobject_trash' => array(), 'ezurlwildcard' => array(), 'ezmedia' => array(), 'ezkeyword' => array());
        $handler = $this->getDatabaseHandler();
        foreach ($data as $table => $rows) {
            // Cleanup before inserting
            $deleteQuery = $handler->createDeleteQuery();
            $deleteQuery->deleteFrom($handler->quoteIdentifier($table));
            $stmt = $deleteQuery->prepare();
            $stmt->execute();
            // Check that at least one row exists
            if (!isset($rows[0])) {
                continue;
            }
            $q = $handler->createInsertQuery();
            $q->insertInto($handler->quoteIdentifier($table));
            // Contains the bound parameters
            $values = array();
            // Binding the parameters
            foreach ($rows[0] as $col => $val) {
                $q->set($handler->quoteIdentifier($col), $q->bindParam($values[$col]));
            }
            $stmt = $q->prepare();
            foreach ($rows as $row) {
                try {
                    // This CANNOT be replaced by:
                    // $values = $row
                    // each $values[$col] is a PHP reference which should be
                    // kept for parameters binding to work
                    foreach ($row as $col => $val) {
                        $values[$col] = $val;
                    }
                    $stmt->execute();
                } catch (Exception $e) {
                    echo "{$table} ( ", implode(', ', $row), " )\n";
                    throw $e;
                }
            }
        }
        $this->applyStatements($this->getPostInsertStatements($dbType));
    }