Beispiel #1
0
 public function __construct()
 {
     $this->extensions = new Map();
     $this->packages = new Map();
     // load up all extensions
     $exts = ExtensionQuery::create()->joinPackage()->find();
     foreach ($exts as $ext) {
         /* @var $ext Extension */
         $key = $ext->getKey();
         $packageName = $ext->getPackage()->getName();
         $data = Json::decode($ext->getData());
         // add to global extensions
         if (!$this->extensions->has($key)) {
             $this->extensions->set($key, new ArrayList());
         }
         $this->extensions->get($key)->add($data);
         // add to package extensions
         if (!$this->packages->has($packageName)) {
             $this->packages->set($packageName, new Map());
         }
         $pkg = $this->packages->get($packageName);
         if (!$pkg->has($key)) {
             $pkg->set($key, new ArrayList());
         }
         $pkg->get($key)->add($data);
     }
 }
 protected function updateExtensions(Package &$model, KeekoPackageSchema $pkg)
 {
     // remove all existing extensions from this package first
     ExtensionQuery::create()->filterByPackage($model)->delete();
     // add them one by one
     foreach ($pkg->getAllExtensions() as $key => $exts) {
         foreach ($exts as $data) {
             $ext = new Extension();
             $ext->setKey($key);
             $ext->setData(Json::encode($data, Json::UNESCAPED_SLASHES));
             $ext->setPackage($model);
             $ext->save();
         }
     }
 }
Beispiel #3
0
 /**
  * Performs an INSERT on the database, given a Extension or Criteria object.
  *
  * @param mixed               $criteria Criteria or Extension object containing data that is used to create the INSERT statement.
  * @param ConnectionInterface $con the ConnectionInterface connection to use
  * @return mixed           The new primary key.
  * @throws PropelException Any exceptions caught during processing will be
  *                         rethrown wrapped into a PropelException.
  */
 public static function doInsert($criteria, ConnectionInterface $con = null)
 {
     if (null === $con) {
         $con = Propel::getServiceContainer()->getWriteConnection(ExtensionTableMap::DATABASE_NAME);
     }
     if ($criteria instanceof Criteria) {
         $criteria = clone $criteria;
         // rename for clarity
     } else {
         $criteria = $criteria->buildCriteria();
         // build Criteria from Extension object
     }
     if ($criteria->containsKey(ExtensionTableMap::COL_ID) && $criteria->keyContainsValue(ExtensionTableMap::COL_ID)) {
         throw new PropelException('Cannot insert a value for auto-increment primary key (' . ExtensionTableMap::COL_ID . ')');
     }
     // Set the correct dbName
     $query = ExtensionQuery::create()->mergeWith($criteria);
     // use transaction because $criteria could contain info
     // for more than one table (I guess, conceivably)
     return $con->transaction(function () use($con, $query) {
         return $query->doInsert($con);
     });
 }
Beispiel #4
0
 /**
  * Returns the number of related Extension objects.
  *
  * @param      Criteria $criteria
  * @param      boolean $distinct
  * @param      ConnectionInterface $con
  * @return int             Count of related Extension objects.
  * @throws PropelException
  */
 public function countExtensions(Criteria $criteria = null, $distinct = false, ConnectionInterface $con = null)
 {
     $partial = $this->collExtensionsPartial && !$this->isNew();
     if (null === $this->collExtensions || null !== $criteria || $partial) {
         if ($this->isNew() && null === $this->collExtensions) {
             return 0;
         }
         if ($partial && !$criteria) {
             return count($this->getExtensions());
         }
         $query = ChildExtensionQuery::create(null, $criteria);
         if ($distinct) {
             $query->distinct();
         }
         return $query->filterByPackage($this)->count($con);
     }
     return count($this->collExtensions);
 }
Beispiel #5
0
 /**
  * Builds a Criteria object containing the primary key for this object.
  *
  * Unlike buildCriteria() this method includes the primary key values regardless
  * of whether or not they have been modified.
  *
  * @throws LogicException if no primary key is defined
  *
  * @return Criteria The Criteria object containing value(s) for primary key(s).
  */
 public function buildPkeyCriteria()
 {
     $criteria = ChildExtensionQuery::create();
     $criteria->add(ExtensionTableMap::COL_ID, $this->id);
     return $criteria;
 }
Beispiel #6
0
 /**
  * Returns one Extension with the given id from cache
  * 
  * @param mixed $id
  * @return Extension|null
  */
 protected function get($id)
 {
     if ($this->pool === null) {
         $this->pool = new Map();
     } else {
         if ($this->pool->has($id)) {
             return $this->pool->get($id);
         }
     }
     $model = ExtensionQuery::create()->findOneById($id);
     $this->pool->set($id, $model);
     return $model;
 }
Beispiel #7
0
 /**
  * Returns a new ChildExtensionQuery object.
  *
  * @param     string $modelAlias The alias of a model in the query
  * @param     Criteria $criteria Optional Criteria to build the query from
  *
  * @return ChildExtensionQuery
  */
 public static function create($modelAlias = null, Criteria $criteria = null)
 {
     if ($criteria instanceof ChildExtensionQuery) {
         return $criteria;
     }
     $query = new ChildExtensionQuery();
     if (null !== $modelAlias) {
         $query->setModelAlias($modelAlias);
     }
     if ($criteria instanceof Criteria) {
         $query->mergeWith($criteria);
     }
     return $query;
 }