/** * Export the sample data */ public function dataexportAction() { $dsn = Shineisp_Main::getDSN(); $conn = Doctrine_Manager::connection($dsn, 'doctrine'); $conn->execute('SHOW TABLES'); # Lazy loading of the connection. If I execute a simple command the connection to the database starts. $conn->setAttribute(Doctrine::ATTR_USE_NATIVE_ENUM, true); $conn->setCharset('UTF8'); // clean up the fixture directory Shineisp_Commons_Utilities::delTree(APPLICATION_PATH . "/configs/data/fixtures/"); @mkdir(APPLICATION_PATH . "/configs/data/fixtures/"); // Set the current connection $manager = Doctrine_Manager::getInstance()->setCurrentConnection('doctrine'); if ($conn->isConnected()) { #Doctrine_Core::dumpData(APPLICATION_PATH . "/configs/data/fixtures/", false); $export = new Doctrine_Data_Export(APPLICATION_PATH . "/configs/data/fixtures/"); $export->setFormat('yml'); $export->setModels(array()); $export->exportIndividualFiles(true); $export->doExport(); } die('done'); }
/** * Create the ShineISP Database */ public static function createDb($installsampledata = true) { try { $dbconfig = Shineisp_Main::databaseConfig(); $dsn = Shineisp_Main::getDSN(); $conn = Doctrine_Manager::connection($dsn, 'doctrine'); $conn->execute('SHOW TABLES'); # Lazy loading of the connection. If I execute a simple command the connection to the database starts. $conn->setAttribute(Doctrine::ATTR_USE_NATIVE_ENUM, true); $conn->setCharset('UTF8'); $dbh = $conn->getDbh(); $models = Doctrine::getLoadedModels(); // Set the current connection $manager = Doctrine_Manager::getInstance()->setCurrentConnection('doctrine'); if ($conn->isConnected()) { $migration = new Doctrine_Migration(APPLICATION_PATH . '/configs/migrations'); // Get the latest version set in the migrations directory $latestversion = $migration->getLatestVersion(); if (empty($latestversion)) { $latestversion = 0; } // Clean the database $conn->execute('SET FOREIGN_KEY_CHECKS = 0'); foreach ($models as $model) { $tablename = Doctrine::getTable($model)->getTableName(); $dbh->query("DROP TABLE IF EXISTS {$tablename}"); } // Create the migration_version table Doctrine_Manager::getInstance()->getCurrentConnection()->execute('DROP TABLE IF EXISTS `migration_version`;CREATE TABLE `migration_version` (`version` int(11) DEFAULT NULL) ENGINE=InnoDB DEFAULT CHARSET=latin1;INSERT INTO `migration_version` VALUES (' . $latestversion . ')'); // Create all the tables in the database Doctrine_Core::createTablesFromModels(APPLICATION_PATH . '/models'); // Common resources Doctrine_Core::loadData(APPLICATION_PATH . '/configs/data/fixtures/commons/', true); // Sample data if ($installsampledata) { $import = new Doctrine_Data_Import(APPLICATION_PATH . '/configs/data/fixtures/'); $import->setFormat('yml'); $import->setModels($models); $import->doImport(true); } $conn->execute('SET FOREIGN_KEY_CHECKS = 1'); // Update the version in the config.xml file previously created Settings::saveConfig($dbconfig, $latestversion); } else { echo "No Connection found"; } } catch (Exception $e) { die($e); } // return the latest version return $latestversion; }