/**
  * Counts the number of instances that exists of the identified type.
  *
  * @param int $typeId
  *
  * @return int
  */
 public function countInstancesOfType($typeId)
 {
     $q = $this->dbHandler->createSelectQuery();
     $q->select($q->alias($q->expr->count($this->dbHandler->quoteColumn('id')), 'count'))->from($this->dbHandler->quoteTable('ezcontentobject'))->where($q->expr->eq($this->dbHandler->quoteColumn('contentclass_id'), $q->bindValue($typeId, null, \PDO::PARAM_INT)));
     $stmt = $q->prepare();
     $stmt->execute();
     return (int) $stmt->fetchColumn();
 }
 /**
  * Loads all autogenerated entries with given $parentId with optionally included history entries.
  *
  * @param mixed $parentId
  * @param boolean $includeHistory
  *
  * @return array
  */
 public function loadAutogeneratedEntries($parentId, $includeHistory = false)
 {
     /** @var $query \ezcQuerySelect */
     $query = $this->dbHandler->createSelectQuery();
     $query->select("*")->from($this->dbHandler->quoteTable("ezurlalias_ml"))->where($query->expr->lAnd($query->expr->eq($this->dbHandler->quoteColumn("parent"), $query->bindValue($parentId, null, \PDO::PARAM_INT)), $query->expr->eq($this->dbHandler->quoteColumn("action_type"), $query->bindValue("eznode", null, \PDO::PARAM_STR)), $query->expr->eq($this->dbHandler->quoteColumn("is_alias"), $query->bindValue(0, null, \PDO::PARAM_INT))));
     if (!$includeHistory) {
         $query->where($query->expr->eq($this->dbHandler->quoteColumn("is_original"), $query->bindValue(1, null, \PDO::PARAM_INT)));
     }
     $statement = $query->prepare();
     $statement->execute();
     return $statement->fetchAll(\PDO::FETCH_ASSOC);
 }
 /**
  * Returns the current version number for a given workflow name.
  *
  * @param  string $workflowName
  * @return int
  * @throws ezcDbException
  */
 protected function getCurrentVersionNumber($workflowName)
 {
     $query = $this->db->createSelectQuery();
     $query->select($query->alias($query->expr->max($this->db->quoteIdentifier('workflow_version')), 'version'))->from($this->db->quoteIdentifier($this->options['prefix'] . 'workflow'))->where($query->expr->eq($this->db->quoteIdentifier('workflow_name'), $query->bindValue($workflowName)));
     $stmt = $query->prepare();
     $stmt->execute();
     $result = $stmt->fetchAll(PDO::FETCH_ASSOC);
     if ($result !== false && isset($result[0]['version']) && $result[0]['version'] !== null) {
         return $result[0]['version'];
     } else {
         return 0;
     }
 }
 /**
  * Generates a basic find query with relation pre-fetching.
  *
  * This method generates a basic find query for the table/class defined in
  * $srcDef, with relation pre-fetching for $relations.
  * 
  * @param ezcPersistentObjectDefinition $srcDef 
  * @param array(string=>ezcPersistentRelationFindDefinition) $relations
  * @return ezcQuerySelect
  */
 protected function createBasicFindQuery(ezcPersistentObjectDefinition $srcDef, array $relations)
 {
     $this->fetchDefinitions($srcDef, $relations);
     $q = $this->db->createSelectQuery();
     // Select the desired object columns as main
     $q->select($q->alias($this->getColumnName($srcDef->table, $srcDef->idProperty->columnName), $this->db->quoteIdentifier($srcDef->idProperty->propertyName)));
     $this->registerAlias($this->getColumnName($srcDef->table, $srcDef->idProperty->columnName), $srcDef->idProperty->propertyName);
     foreach ($srcDef->properties as $property) {
         $q->select($q->alias($this->getColumnName($srcDef->table, $property->columnName), $this->db->quoteIdentifier($property->propertyName)));
         $this->registerAlias($this->getColumnName($srcDef->table, $property->columnName), $property->propertyName);
     }
     $this->createSelects($q, $relations);
     $q->from($this->db->quoteIdentifier($srcDef->table));
     $this->createJoins($q, $srcDef->table, $relations);
     return $q;
 }
示例#5
0
文件: execution.php 项目: bmdevel/ezc
 /**
  * Load execution state.
  *
  * @param int $executionId  ID of the execution to load.
  * @throws ezcWorkflowExecutionException
  */
 protected function loadExecution($executionId)
 {
     $query = $this->db->createSelectQuery();
     $query->select($this->db->quoteIdentifier('workflow_id'))->select($this->db->quoteIdentifier('execution_variables'))->select($this->db->quoteIdentifier('execution_threads'))->select($this->db->quoteIdentifier('execution_next_thread_id'))->select($this->db->quoteIdentifier('execution_waiting_for'))->from($this->db->quoteIdentifier($this->options['prefix'] . 'execution'))->where($query->expr->eq($this->db->quoteIdentifier('execution_id'), $query->bindValue((int) $executionId)));
     $stmt = $query->prepare();
     $stmt->execute();
     $result = $stmt->fetchAll(PDO::FETCH_ASSOC);
     if ($result === false || empty($result)) {
         throw new ezcWorkflowExecutionException('Could not load execution state.');
     }
     $this->id = $executionId;
     $this->nextThreadId = $result[0]['execution_next_thread_id'];
     $this->threads = ezcWorkflowDatabaseUtil::unserialize($result[0]['execution_threads']);
     $this->variables = ezcWorkflowDatabaseUtil::unserialize($result[0]['execution_variables']);
     $this->waitingFor = ezcWorkflowDatabaseUtil::unserialize($result[0]['execution_waiting_for']);
     $workflowId = $result[0]['workflow_id'];
     $this->workflow = $this->properties['definitionStorage']->loadById($workflowId);
     $query = $this->db->createSelectQuery();
     $query->select($this->db->quoteIdentifier('node_id'))->select($this->db->quoteIdentifier('node_state'))->select($this->db->quoteIdentifier('node_activated_from'))->select($this->db->quoteIdentifier('node_thread_id'))->from($this->db->quoteIdentifier($this->options['prefix'] . 'execution_state'))->where($query->expr->eq($this->db->quoteIdentifier('execution_id'), $query->bindValue((int) $executionId)));
     $stmt = $query->prepare();
     $stmt->execute();
     $result = $stmt->fetchAll(PDO::FETCH_ASSOC);
     $active = array();
     foreach ($result as $row) {
         $active[$row['node_id']] = array('activated_from' => ezcWorkflowDatabaseUtil::unserialize($row['node_activated_from']), 'state' => ezcWorkflowDatabaseUtil::unserialize($row['node_state'], null), 'thread_id' => $row['node_thread_id']);
     }
     foreach ($this->workflow->nodes as $node) {
         $nodeId = $node->getId();
         if (isset($active[$nodeId])) {
             $node->setActivationState(ezcWorkflowNode::WAITING_FOR_EXECUTION);
             $node->setThreadId($active[$nodeId]['thread_id']);
             $node->setState($active[$nodeId]['state'], null);
             $node->setActivatedFrom($active[$nodeId]['activated_from']);
             $this->activate($node, false);
         }
     }
     $this->cancelled = false;
     $this->ended = false;
     $this->loaded = true;
     $this->resumed = false;
     $this->suspended = true;
 }
 /**
  * Returns true if the object is persistent already.
  *
  * Called in the beginning of the save process.
  *
  * Persistent objects that are being saved must not exist in the database already.
  *
  * @param ezcPersistentObjectDefinition $def
  * @param ezcDbHandler $db
  * @param array(key=>value) $state
  * @return void
  */
 public function checkPersistence(ezcPersistentObjectDefinition $def, ezcDbHandler $db, array $state)
 {
     // store id
     $this->id = $state[$def->idProperty->propertyName];
     // check if there is an object with this id already
     $q = $db->createSelectQuery();
     $q->select('*')->from($db->quoteIdentifier($def->table))->where($q->expr->eq($db->quoteIdentifier($def->idProperty->columnName), $q->bindValue($this->id, null, $def->idProperty->databaseType)));
     try {
         $stmt = $q->prepare();
         $stmt->execute();
     } catch (PDOException $e) {
         throw new ezcPersistentQueryException($e->getMessage(), $q);
     }
     $row = $stmt->fetch(PDO::FETCH_ASSOC);
     $stmt->closeCursor();
     if ($row !== false) {
         return true;
     }
     return false;
 }