1:  2:  3:  4:  5:  6:  7:  8:  9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 
<?php
namespace Omeka\Installation\Task;

use Doctrine\DBAL\DBALException;
use Omeka\Installation\Installer;

/**
 * Install schema task.
 */
class InstallSchemaTask implements TaskInterface
{
    public function perform(Installer $installer)
    {
        $schemaPath = OMEKA_PATH . '/application/data/install/schema.sql';
        if (!is_readable($schemaPath)) {
            $installer->addError('Could not read the schema installation file.');
            return;
        }

        $schema = file_get_contents($schemaPath);
        $statements = explode(';', $schema);
        $connection = $installer->getServiceLocator()->get('Omeka\Connection');
        try {
            foreach ($statements as $statement) {
                $statement = trim($statement);
                if ('' === $statement) {
                    continue;
                }
                $connection->exec($statement);
            }
        } catch (DBALException $e) {
            $installer->addError($e->getMessage());
            return;
        }
    }
}