本文整理汇总了PHP中Doctrine::getLoadedModels方法的典型用法代码示例。如果您正苦于以下问题:PHP Doctrine::getLoadedModels方法的具体用法?PHP Doctrine::getLoadedModels怎么用?PHP Doctrine::getLoadedModels使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine
的用法示例。
在下文中一共展示了Doctrine::getLoadedModels方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setup
public function setup()
{
$db = $this->databasemanager->getDatabase('doctrine');
/* @var $db sfDoctrineDatabase */
// Special Handling for postgre, since droping even when closing the connection, fails with
// SQLSTATE[55006]: Object in use: 7 ERROR: database "cs_doctrine_act_as_sortable_test" is being accessed by other users DETAIL: There are 1 other session(s) using the database.
if ($db->getDoctrineConnection() instanceof Doctrine_Connection_Pgsql) {
try {
$db->getDoctrineConnection()->createDatabase();
} catch (Exception $e) {
}
$export = new Doctrine_Export_Pgsql($db->getDoctrineConnection());
$import = new Doctrine_Import_Pgsql($db->getDoctrineConnection());
$tablenames = array(SortableArticleTable::getInstance()->getTableName(), SortableArticleUniqueByTable::getInstance()->getTableName(), SortableArticleCategoryTable::getInstance()->getTableName());
foreach ($tablenames as $tablename) {
if ($import->tableExists($tablename)) {
$export->dropTable($tablename);
}
}
} else {
try {
// ignore error if database does not yet exist (clean CI-env)
$db->getDoctrineConnection()->dropDatabase();
} catch (Exception $e) {
}
$db->getDoctrineConnection()->createDatabase();
}
// Using Doctrine instead of Doctrine_Core keeps it symfony 1.2 compatible, which uses
Doctrine::loadModels(dirname(__FILE__) . '/../fixtures/project/lib/model/doctrine', Doctrine::MODEL_LOADING_CONSERVATIVE);
Doctrine::createTablesFromArray(Doctrine::getLoadedModels());
Doctrine::loadData(dirname(__FILE__) . '/../fixtures/project/data/fixtures/categories.yml');
}
示例2: execute
/**
* @see sfTask
*/
protected function execute($arguments = array(), $options = array())
{
$this->logSection('doctrine', 'created tables successfully');
$databaseManager = new sfDatabaseManager($this->configuration);
Doctrine::loadModels(sfConfig::get('sf_lib_dir') . '/model/doctrine', Doctrine::MODEL_LOADING_CONSERVATIVE);
Doctrine::createTablesFromArray(Doctrine::getLoadedModels());
}
示例3: doExport
/**
* doExport
*
* FIXME: This function has ugly hacks in it for temporarily disabling INDEXBY query parts of tables
* to export.
*
* Update from jwage: I am not sure if their is any other better solution for this. It may be the correct
* solution to disable the indexBy settings for tables when exporting data fixtures. Maybe a better idea
* would be to extract this functionality to a pair of functions to enable/disable the index by settings
* so simply turn them on and off when they need to query for the translations standalone and don't need
* it to be indexed by the lang.
*
* @return void
*/
public function doExport()
{
$models = Doctrine::getLoadedModels();
$specifiedModels = $this->getModels();
$data = array();
// for situation when the $models array is empty, but the $specifiedModels array isn't
if (empty($models)) {
$models = $specifiedModels;
}
$models = Doctrine::initializeModels($models);
// temporarily disable indexBy query parts of selected and related tables
$originalIndexBy = array();
foreach ($models as $name) {
$table = Doctrine::getTable($name);
if (!is_null($indexBy = $table->getBoundQueryPart('indexBy'))) {
$originalIndexBy[$name] = $indexBy;
$table->bindQueryPart('indexBy', null);
}
}
foreach ($models as $name) {
if (!empty($specifiedModels) and !in_array($name, $specifiedModels)) {
continue;
}
$results = Doctrine::getTable($name)->findAll();
if ($results->count() > 0) {
$data[$name] = $results;
}
}
// Restore the temporarily disabled indexBy query parts
foreach ($originalIndexBy as $name => $indexBy) {
Doctrine::getTable($name)->bindQueryPart('indexBy', $indexBy);
}
$data = $this->prepareData($data);
return $this->dumpData($data);
}
示例4: testModelLoadingCacheInformation
public function testModelLoadingCacheInformation()
{
$models = Doctrine::getLoadedModels();
$this->assertTrue(in_array('AggressiveModelLoadingUser', $models));
$this->assertTrue(in_array('ConservativeModelLoadingProfile', $models));
$this->assertTrue(in_array('ConservativeModelLoadingContact', $models));
$modelFiles = Doctrine::getLoadedModelFiles();
$this->assertTrue(file_exists($modelFiles['ConservativeModelLoadingUser']));
$this->assertTrue(file_exists($modelFiles['ConservativeModelLoadingProfile']));
$this->assertTrue(file_exists($modelFiles['ConservativeModelLoadingContact']));
}
示例5: buildSchema
/**
* buildSchema
*
* Build schema array that can be dumped to file
*
* @param string $directory
* @return void
*/
public function buildSchema($directory = null, $models = array())
{
if ($directory) {
$loadedModels = Doctrine::loadModels($directory);
} else {
$loadedModels = Doctrine::getLoadedModels();
}
$array = array();
$parent = new ReflectionClass('Doctrine_Record');
$sql = array();
$fks = array();
// we iterate trhough the diff of previously declared classes
// and currently declared classes
foreach ($loadedModels as $className) {
if (!empty($models) && !in_array($className, $models)) {
continue;
}
$record = new $className();
$recordTable = $record->getTable();
$data = $recordTable->getExportableFormat();
$table = array();
foreach ($data['columns'] as $name => $column) {
$data['columns'][$name]['type'] = $column['type'] . '(' . $column['length'] . ')';
unset($data['columns'][$name]['length']);
}
$table['columns'] = $data['columns'];
$relations = $recordTable->getRelations();
foreach ($relations as $key => $relation) {
$relationData = $relation->toArray();
$relationKey = $relationData['alias'];
if (isset($relationData['refTable']) && $relationData['refTable']) {
$table['relations'][$relationKey]['refClass'] = $relationData['refTable']->getComponentName();
}
if (isset($relationData['class']) && $relationData['class'] && $relation['class'] != $relationKey) {
$table['relations'][$relationKey]['class'] = $relationData['class'];
}
$table['relations'][$relationKey]['local'] = $relationData['local'];
$table['relations'][$relationKey]['foreign'] = $relationData['foreign'];
if ($relationData['type'] === Doctrine_Relation::ONE) {
$table['relations'][$relationKey]['type'] = 'one';
} else {
if ($relationData['type'] === Doctrine_Relation::MANY) {
$table['relations'][$relationKey]['type'] = 'many';
} else {
$table['relations'][$relationKey]['type'] = 'one';
}
}
}
$array[$className] = $table;
}
return $array;
}
示例6: execute
protected function execute($arguments = array(), $options = array())
{
$configuration = ProjectConfiguration::getApplicationConfiguration($options['application'], $options['env'], true);
$databaseManager = new sfDatabaseManager($configuration);
$databaseManager->initialize($configuration);
$dir = sfConfig::get('sf_data_dir') . DIRECTORY_SEPARATOR . 'fixtures';
$excludedModels = array('Modification', 'ModificationField');
Doctrine::loadModels(sfConfig::get('sf_lib_dir') . DIRECTORY_SEPARATOR . 'model' . DIRECTORY_SEPARATOR . 'doctrine');
$loadedModels = Doctrine::getLoadedModels();
$models = array_diff($loadedModels, $excludedModels);
$data = new Doctrine_Data();
$data->exportData($dir, 'yml', $models, false);
}
示例7: buildDBFromModels
/**
* Rebuilds a db as described by the doctrine models
*
*/
public function buildDBFromModels()
{
$icinga = $this->project->getUserProperty("PATH_Icinga");
$modelPath = $icinga . "/app/modules/" . $this->project->getUserProperty("MODULE_Name") . "/lib/";
$appKitPath = $this->project->getUserProperty("PATH_AppKit");
Doctrine::loadModels($icinga . "/" . $appKitPath . "database/models/generated/");
Doctrine::loadModel($icinga . "/" . $appKitPath . "database/models/");
$tables = Doctrine::getLoadedModels();
$tableList = array();
foreach ($tables as $table) {
$tableList[] = Doctrine::getTable($table)->getTableName();
}
Doctrine::createTablesFromModels(array($this->models . '/generated', $this->models));
file_put_contents($modelPath . "/.models.cfg", implode(",", $tableList));
}
示例8: clearData
public function clearData()
{
Doctrine::loadModels(sfConfig::get('sf_lib_dir') . '/model/doctrine');
$models = Doctrine::getLoadedModels();
foreach ($models as $model) {
try {
Doctrine::getTable($model)->createQuery()->delete()->execute();
} catch (Doctrine_Connection_Exception $e) {
// if couldn't delete the first time, try it again at the end
$models[] = $model;
unset($models[array_search($model, $models)]);
}
}
return $this;
}
示例9: removeTables
private function removeTables()
{
$integrity_violation = 0;
$models = Doctrine::getLoadedModels();
foreach ($models as $model) {
try {
$Model = new $model();
$table = $Model->getTable()->tableName;
Doctrine_Manager::connection()->export->dropTable($table);
} catch (Exception $e) {
if ($e->getCode() == 23000) {
// 23000: Integrity constraint violation
$integrity_violation = 1;
}
}
}
if ($integrity_violation == 1) {
$integrity_violation = 0;
$this->removeTables();
}
}
示例10: doExport
/**
* doExport
*
* @return void
*/
public function doExport()
{
$models = Doctrine::getLoadedModels();
$specifiedModels = $this->getModels();
$data = array();
// for situation when the $models array is empty, but the $specifiedModels array isn't
if (empty($models)) {
$models = $specifiedModels;
}
$models = Doctrine::initializeModels($models);
foreach ($models as $name) {
if (!empty($specifiedModels) and !in_array($name, $specifiedModels)) {
continue;
}
$results = Doctrine::getTable($name)->findAll();
if ($results->count() > 0) {
$data[$name] = $results;
}
}
$data = $this->prepareData($data);
return $this->dumpData($data);
}
示例11: index
public function index()
{
$loadedModels = Doctrine::getLoadedModels();
$driver = Telephony::getDriver();
$driverName = get_class($driver);
// If no driver is set, just return w/ FALSE.
if (!$driver) {
return FALSE;
}
foreach ($loadedModels as $model) {
$modelDriverName = $driverName . '_' . $model . '_Driver';
if (!class_exists($modelDriverName, TRUE)) {
continue;
}
$outputRows = Doctrine::getTable($model)->findAll();
foreach ($outputRows as $outputRow) {
Telephony::set($outputRow, $outputRow->identifier());
}
}
Telephony::save();
Telephony::commit();
}
示例12: account
public function account($account_id = NULL, $redirect = TRUE)
{
if ($account_id && users::masqueradeAccount($account_id)) {
$masquerade_account = TRUE;
}
$loadedModels = Doctrine::getLoadedModels();
$driver = Telephony::getDriver();
$driverName = get_class($driver);
if (!$driver) {
message::set('Can not rebuild configuration, no telephony driver active');
} else {
try {
foreach ($loadedModels as $model) {
$modelDriverName = $driverName . '_' . $model . '_Driver';
if (!class_exists($modelDriverName, TRUE)) {
continue;
}
$outputRows = Doctrine::getTable($model)->findAll();
foreach ($outputRows as $outputRow) {
Telephony::set($outputRow, $outputRow->identifier());
}
}
Telephony::save();
Telephony::commit();
$account = Doctrine::getTable('Account')->find(users::getAttr('account_id'));
parent::save_succeeded($account);
message::set(users::getAttr('Account', 'name') . ' configuration rebuild complete!', 'success');
} catch (Exception $e) {
message::set($e->getMessage());
}
}
if (!empty($masquerade_account)) {
users::restoreAccount();
}
$this->returnQtipAjaxForm();
if ($redirect) {
url::redirect(Router_Core::$controller);
}
}
示例13: doExport
/**
* doExport
*
* @return void
*/
public function doExport()
{
$models = Doctrine::getLoadedModels();
$specifiedModels = $this->getModels();
$data = array();
$outputAll = true;
// for situation when the $models array is empty, but the $specifiedModels array isn't
if (empty($models)) {
$models = $specifiedModels;
}
foreach ($models as $name) {
if (!empty($specifiedModels) and !in_array($name, $specifiedModels)) {
continue;
}
$class = new $name();
$table = $class->getTable();
$result = $table->findAll();
if (!empty($result)) {
$data[$name] = $result;
}
}
$data = $this->prepareData($data);
return $this->dumpData($data);
}
示例14: updateStructure
public function updateStructure()
{
echo "\nUpdating DB Structure\n";
$models = Doctrine::loadModels($this->modelPath, Doctrine_Core::MODEL_LOADING_AGGRESSIVE, "Nsm");
$allAltered = array();
foreach (Doctrine::getLoadedModels() as $model) {
$class = new $model();
$altered = array();
//test
$cols = $class->getTable()->getColumns();
$tn = $class->getTable()->getTableName();
$conn = Doctrine_Manager::connection();
foreach ($cols as $name => $columns) {
try {
$conn->export->alterTable($tn, array(add => array($name => $columns)));
$altered[] = $name;
echo "Added column " . $name . " to " . $model . "\n";
} catch (Exception $e) {
}
}
$allAltered[$model] = $altered;
}
return $allAltered;
}
示例15: generateMigrationsFromModels
/**
* generateMigrationsFromModels
*
* @param string $modelsPath
* @return void
*/
public function generateMigrationsFromModels($modelsPath = null, $modelLoading = null)
{
if ($modelsPath !== null) {
$models = Doctrine::filterInvalidModels(Doctrine::loadModels($modelsPath, $modelLoading));
} else {
$models = Doctrine::getLoadedModels();
}
$models = Doctrine::initializeModels($models);
$foreignKeys = array();
foreach ($models as $model) {
$export = Doctrine::getTable($model)->getExportableFormat();
$foreignKeys[$export['tableName']] = $export['options']['foreignKeys'];
$up = $this->buildCreateTable($export);
$down = $this->buildDropTable($export);
$className = 'Add' . Doctrine_Inflector::classify($export['tableName']);
$this->generateMigrationClass($className, array(), $up, $down);
}
if (!empty($foreignKeys)) {
$className = 'ApplyForeignKeyConstraints';
$up = '';
$down = '';
foreach ($foreignKeys as $tableName => $definitions) {
$tableForeignKeyNames[$tableName] = array();
foreach ($definitions as $definition) {
$definition['name'] = $tableName . '_' . implode('_', (array) $definition['local']);
$up .= $this->buildCreateForeignKey($tableName, $definition);
$down .= $this->buildDropForeignKey($tableName, $definition);
}
}
$this->generateMigrationClass($className, array(), $up, $down);
}
return true;
}