/** * 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_Core::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_Core::initializeModels($models); // temporarily disable indexBy query parts of selected and related tables $originalIndexBy = array(); foreach ($models as $name) { $table = Doctrine_Core::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_Core::getTable($name)->findAll(); if ($results->count() > 0) { $data[$name] = $results; } } // Restore the temporarily disabled indexBy query parts foreach ($originalIndexBy as $name => $indexBy) { Doctrine_Core::getTable($name)->bindQueryPart('indexBy', $indexBy); } $data = $this->prepareData($data); return $this->dumpData($data); }
public function getFullTypeQuery($type, $alias = 'c', $contentTypeId = null) { if (is_numeric($type)) { $type = Doctrine_Core::getTable('sfSympalContentType')->find($type); } if ($type instanceof sfSympalContentType) { $table = $type->getTable(); $typeModelName = $type->getName(); } else { $table = Doctrine_Core::getTable($type); $typeModelName = $type; } Doctrine_Core::initializeModels(array($typeModelName)); $q = $this->getBaseQuery($alias); if ($type instanceof sfSympalContentType) { $contentTypeId = $type->getId(); } if ($contentTypeId) { $q->innerJoin($alias . '.' . $typeModelName . ' cr WITH ' . $alias . '.content_type_id = ' . $contentTypeId); } else { $q->innerJoin($alias . '.' . $typeModelName . ' cr'); } if (sfSympalConfig::isI18nEnabled($typeModelName)) { $q->leftJoin('cr.Translation crt'); } if (method_exists($table, 'getContentQuery')) { $table->getContentQuery($q); } return $q; }
/** * Loads all model classes and returns an array of model names. * * @return array An array of model names */ protected function loadModels() { Doctrine_Core::loadModels($this->configuration->getModelDirs()); $models = Doctrine_Core::getLoadedModels(); $models = Doctrine_Core::initializeModels($models); $models = Doctrine_Core::filterInvalidModels($models); return $models; }
/** * Generate a diff between the from and to schema information * * @param string $from Path to set of models to migrate from * @param string $to Path to set of models to migrate to * @return array $changes */ protected function _diff($from, $to) { // Load the from and to models $fromModels = Doctrine_Core::initializeModels(Doctrine_Core::loadModels($from)); $toModels = Doctrine_Core::initializeModels(Doctrine_Core::loadModels($to)); // Build schema information for the models $fromInfo = $this->_buildModelInformation($fromModels); $toInfo = $this->_buildModelInformation($toModels); // Build array of changes between the from and to information $changes = $this->_buildChanges($fromInfo, $toInfo); $this->_cleanup(); return $changes; }
/** * Generate a set of migrations from a set of models * * @param string $modelsPath Path to models * @param string $modelLoading What type of model loading to use when loading the models * @return boolean */ public function generateMigrationsFromModels($modelsPath = null, $modelLoading = null) { if ($modelsPath !== null) { $models = Doctrine_Core::filterInvalidModels(Doctrine_Core::loadModels($modelsPath, $modelLoading)); } else { $models = Doctrine_Core::getLoadedModels(); } $models = Doctrine_Core::initializeModels($models); $foreignKeys = array(); foreach ($models as $model) { $table = Doctrine_Core::getTable($model); if ($table->getTableName() !== $this->migration->getTableName()) { $export = $table->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 = 'AddFks'; $up = array(); $down = array(); foreach ($foreignKeys as $tableName => $definitions) { $tableForeignKeyNames[$tableName] = array(); foreach ($definitions as $definition) { $up[] = $this->buildCreateForeignKey($tableName, $definition); $down[] = $this->buildDropForeignKey($tableName, $definition); } } $up = implode("\n", $up); $down = implode("\n", $down); if ($up || $down) { $this->generateMigrationClass($className, array(), $up, $down); } } return true; }
/** * Loads all Doctrine builders. */ protected function loadModels() { Doctrine_Core::loadModels($this->generatorManager->getConfiguration()->getModelDirs()); $models = Doctrine_Core::getLoadedModels(); $models = Doctrine_Core::initializeModels($models); $models = Doctrine_Core::filterInvalidModels($models); $this->models = $this->filterModels($models); return $this->models; }
/** * Initialize some Doctrine models at a given path. * * @param string $path * @return array $models */ protected function _initializeModels($path) { $manager = Doctrine_Manager::getInstance(); $modelLoading = $manager->getAttribute(Doctrine_Core::ATTR_MODEL_LOADING); if ($modelLoading === Doctrine_Core::MODEL_LOADING_PEAR) { $orig = Doctrine_Core::getModelsDirectory(); Doctrine_Core::setModelsDirectory($path); $models = Doctrine_Core::initializeModels(Doctrine_Core::loadModels($path)); Doctrine_Core::setModelsDirectory($orig); } else { $models = Doctrine_Core::initializeModels(Doctrine_Core::loadModels($path)); } return $models; }
public function getRecord() { if ($this['Type']['name']) { Doctrine_Core::initializeModels(array($this['Type']['name'])); return $this[$this['Type']['name']]; } else { return false; } }
/** * Load builders * * @return array Loaded models */ protected function loadModels() { Doctrine_Core::loadModels(array(sfConfig::get('sf_lib_dir') . '/model')); $this->models = $this->filterModels(Doctrine_Core::filterInvalidModels(Doctrine_Core::initializeModels(Doctrine_Core::getLoadedModels()))); return $this->models; }
/** * Initialize some Doctrine models at a given path. * * @param string $path * @return array $models */ protected function _initializeModels($path) { $orig = Doctrine_Core::getModelsDirectory(); Doctrine_Core::setModelsDirectory($path); $models = Doctrine_Core::initializeModels(Doctrine_Core::loadModels($path)); Doctrine_Core::setModelsDirectory($orig); return $models; }
/** * The actual action that handles creating a new piece of content * * Uses the new template */ public function executeCreate_type(sfWebRequest $request) { $type = $request->getParameter('type'); $this->_getContentType($type, $request); $this->sf_sympal_content = new sfSympalContent(); $this->sf_sympal_content->setType($this->contentType); $this->sf_sympal_content->CreatedBy = $this->getUser()->getGuardUser(); $this->sf_sympal_content->date_published = date('Y-m-d h:i:s'); Doctrine_Core::initializeModels(array($type['name'])); $this->form = new sfSympalContentForm($this->sf_sympal_content); $this->setTemplate('new'); }
public function findVersoesArtigo($artigo) { Doctrine_Core::initializeModels(array('Artigo')); $q = $this->createQuery()->from('ArtigoVersao a')->where('a.id = ?', $artigo)->orderBy('a.version DESC'); return $q->execute(); }
public function executeCreate_type(sfWebRequest $request) { $type = $request->getParameter('type'); if (is_numeric($type)) { $type = Doctrine_Core::getTable('sfSympalContentType')->find($type); } else { $type = Doctrine_Core::getTable('sfSympalContentType')->findOneBySlug($type); } $this->sf_sympal_content = new sfSympalContent(); $this->sf_sympal_content->setType($type); $this->sf_sympal_content->CreatedBy = $this->getUser()->getGuardUser(); Doctrine_Core::initializeModels(array($type['name'])); $this->form = new sfSympalContentForm($this->sf_sympal_content); $this->setTemplate('new'); }