fetchColumn() public method

Prepares and executes an SQL query and returns the value of a single column of the first row of the result.
public fetchColumn ( string $statement, array $params = [], integer $column, array $types = [] ) : mixed | boolean
$statement string The SQL query to be executed.
$params array The prepared statement params.
$column integer The 0-indexed column number to retrieve.
$types array The query parameter types.
return mixed | boolean False is returned if no rows are found.
 protected function doStart($parentId)
 {
     $this->conn->beginTransaction();
     $platform = $this->conn->getDatabasePlatform();
     $variables = $this->variables;
     $executionNextPollDate = null;
     if (isset($variables['batchWaitInterval'])) {
         if (!$variables['batchWaitInterval'] instanceof \DateInterval) {
             throw new \ezcWorkflowExecutionException("Specified batch waiting interval has to be instance of DateInterval!");
         }
         $executionNextPollDate = new \DateTime("now");
         $executionNextPollDate->add($variables['batchWaitInterval']);
         $executionNextPollDate = $executionNextPollDate->format($platform->getDateTimeFormatString());
     }
     $serializer = $this->options->getSerializer();
     $now = new \DateTime("now");
     $data = array('workflow_id' => (int) $this->workflow->id, 'execution_parent' => $parentId, 'execution_started' => $now->format($platform->getDateTimeFormatString()), 'execution_variables' => $serializer->serialize($variables), 'execution_waiting_for' => $serializer->serialize($this->waitingFor), 'execution_threads' => $serializer->serialize($this->threads), 'execution_next_thread_id' => (int) $this->nextThreadId, 'execution_next_poll_date' => $executionNextPollDate);
     if ($platform->prefersSequences()) {
         $data['execution_id'] = (int) $this->conn->fetchColumn($platform->getSequenceNextValSQL($this->options->executionSequence()));
         $this->id = $data['execution_id'];
     }
     $this->conn->insert($this->options->executionTable(), $data);
     // execution_id
     if (!$platform->prefersSequences()) {
         $this->id = (int) $this->conn->lastInsertId();
     }
 }
Exemplo n.º 2
1
 /**
  * @test
  */
 public function shouldBeJson()
 {
     if (false === strpos($this->conn->fetchColumn('SELECT VERSION()'), '5.7')) {
         $this->markTestIncomplete('Only for mysql 5.7');
     }
     $create_query = "create table t1 (i INT, j JSON)";
     $insert_query = "INSERT INTO t1 VALUES \r\n            (0, NULL) , \r\n            (1, '{\"a\": 2}'),\r\n            (2, '[1,2]'),\r\n            (3, '{\"a\":\"b\", \"c\":\"d\",\"ab\":\"abc\", \"bc\": [\"x\", \"y\"]}'),\r\n            (4, '[\"here\", [\"I\", \"am\"], \"!!!\"]'),\r\n            (5, '\"scalar string\"'),\r\n            (6, 'true'),\r\n            (7, 'false'),\r\n            (8, 'null'),\r\n            (9, '-1'),\r\n            (10, CAST(CAST(1 AS UNSIGNED) AS JSON)),\r\n            (11, '32767'),\r\n            (12, '32768'),\r\n            (13, '-32768'),\r\n            (14, '-32769'),\r\n            (15, '2147483647'),\r\n            (16, '2147483648'),\r\n            (17, '-2147483648'),\r\n            (18, '-2147483649'),\r\n            (19, '18446744073709551615'),\r\n            (20, '18446744073709551616'),\r\n            (21, '3.14'),\r\n            (22, '{}'),\r\n            (23, '[]'),\r\n            -- (24, CAST(CAST('2015-01-15 23:24:25' AS DATETIME) AS JSON)),\r\n            -- (25, CAST(CAST('23:24:25' AS TIME) AS JSON)),\r\n            -- (125, CAST(CAST('23:24:25.12' AS TIME(3)) AS JSON)),\r\n            -- (225, CAST(CAST('23:24:25.0237' AS TIME(3)) AS JSON)),\r\n            -- (26, CAST(CAST('2015-01-15' AS DATE) AS JSON)),\r\n            -- (27, CAST(TIMESTAMP'2015-01-15 23:24:25' AS JSON)),\r\n            -- (127, CAST(TIMESTAMP'2015-01-15 23:24:25.12' AS JSON)),\r\n            -- (227, CAST(TIMESTAMP'2015-01-15 23:24:25.0237' AS JSON)),\r\n            -- (327, CAST(UNIX_TIMESTAMP('2015-01-15 23:24:25') AS JSON)),\r\n            -- (28, CAST(ST_GeomFromText('POINT(1 1)') AS JSON)),\r\n            (29, CAST('[]' AS CHAR CHARACTER SET 'ascii')),\r\n            -- (30, CAST(x'cafe' AS JSON)),\r\n            -- (31, CAST(x'cafebabe' AS JSON)),\r\n            (100, CONCAT('{\"', REPEAT('a', 64 * 1024 - 1), '\":123}'))\r\n        ";
     $event = $this->createAndInsertValue($create_query, $insert_query);
     $results = $event->getValues();
     self::assertEquals($results[0]['j'], null);
     self::assertEquals($results[1]['j'], '{"a":2}');
     self::assertEquals($results[2]['j'], '[1,2]');
     self::assertEquals($results[3]['j'], '{"a":"b","c":"d","ab":"abc","bc":["x","y"]}');
     self::assertEquals($results[4]['j'], '["here",["I","am"],"!!!"]');
     self::assertEquals($results[5]['j'], '"scalar string"');
     self::assertEquals($results[6]['j'], 'true');
     self::assertEquals($results[7]['j'], 'false');
     self::assertEquals($results[8]['j'], '"null"');
     self::assertEquals($results[9]['j'], '"-1"');
     self::assertEquals($results[10]['j'], '"1"');
     self::assertEquals($results[11]['j'], '"32767"');
     self::assertEquals($results[12]['j'], '"32768"');
     self::assertEquals($results[13]['j'], '"-32768"');
     self::assertEquals($results[14]['j'], '"-32769"');
     self::assertEquals($results[15]['j'], '"2147483647"');
     self::assertEquals($results[16]['j'], '"2147483648"');
     self::assertEquals($results[17]['j'], '"-2147483648"');
     self::assertEquals($results[18]['j'], '"-2147483649"');
     self::assertEquals($results[19]['j'], '"18446744073709551615"');
     self::assertEquals($results[20]['j'], '"1.844674407371E+19"');
     self::assertEquals($results[21]['j'], '"3.14"');
     self::assertEquals($results[22]['j'], '{}');
     self::assertEquals($results[23]['j'], '[]');
     self::assertEquals($results[24]['j'], '[]');
 }
Exemplo n.º 3
0
 /**
  * {@inheritdoc}
  */
 public function findMask(RequesterInterface $requester, ResourceInterface $resource)
 {
     if (false === ($mask = $this->connection->fetchColumn('SELECT mask FROM ' . $this->getAclSchema()->getPermissionsTableName() . ' WHERE requester = :requester AND resource = :resource', ['requester' => $requester->getAclRequesterIdentifier(), 'resource' => $resource->getAclResourceIdentifier()], 0, ['requester' => \PDO::PARAM_STR, 'resource' => \PDO::PARAM_STR]))) {
         throw new MaskNotFoundException();
     }
     return (int) $mask;
 }
Exemplo n.º 4
0
 /**
  * {@inheritdoc}
  */
 public function find($key, $ttl)
 {
     $data = $this->db->fetchColumn('SELECT user FROM ' . $this->table . ' WHERE id = ? AND time > ?', [$key, time() - $ttl], 0);
     if (!$data) {
         return false;
     }
     return $data;
 }
Exemplo n.º 5
0
 /**
  * {@inheritdoc}
  */
 public function load($id, $ttl)
 {
     $data = $this->db->fetchColumn('SELECT data FROM ' . $this->table . ' WHERE sid = ? AND time > ?', [$id, time() - $ttl], 0);
     if (!$data) {
         return false;
     }
     return unserialize($data);
 }
Exemplo n.º 6
0
	/**
	 * @param $dbName
	 * @return mixed
	 */
	private function countMyIsamTables() {
		$dbName = \OC::$server->getConfig()->getSystemValue("dbname");

		$result = $this->connection->fetchColumn(
			"SELECT count(*) FROM information_schema.tables WHERE table_schema = ? and table_name = ? AND engine = 'MyISAM'",
			array($dbName, $this->tableName)
		);
		return $result;
	}
Exemplo n.º 7
0
 public function findMilestoneProgressForAreasInGroup(Group $group)
 {
     $totalMilestones = $this->conn->fetchColumn('SELECT COUNT(`id`) FROM `' . MilestoneTables::MILESTONE_TBL . '` WHERE `projectId` = :projectId AND `entityType` = \'Area\'', [':projectId' => $group->getProject()->getId()]);
     $results = $this->conn->fetchAll('SELECT a.`id`, a.`name`, a.`entityId`, p.`completedNum` ' . 'FROM `' . CoreTables::AREA_TBL . '` a ' . 'INNER JOIN `' . MilestoneTables::MILESTONE_PROGRESS_TBL . '` p ON p.`entityId` = a.`entityId` ' . 'WHERE a.`groupId` = :groupId ' . 'ORDER BY p.`completedNum` DESC, a.`name`', [':groupId' => $group->getId()]);
     foreach ($results as &$result) {
         $this->processResult($totalMilestones, $result);
     }
     return $results;
 }
Exemplo n.º 8
0
 protected function getInstalledVersion(Schema $schema)
 {
     if ($schema->hasTable('fusio_meta')) {
         $version = $this->connection->fetchColumn('SELECT version FROM fusio_meta ORDER BY installDate DESC, id DESC LIMIT 1');
         if (!empty($version)) {
             return $version;
         }
     }
     return null;
 }
Exemplo n.º 9
0
 /**
  * gets the values of the excellence plugin
  *
  * @return array
  * @param $pluginId
  */
 private function getTsExcellenceData($pluginId)
 {
     $sql = "SELECT id\n                FROM  `s_core_config_forms`\n                WHERE  `plugin_id` = ?";
     $tsExcFormId = $this->db->fetchColumn($sql, array($pluginId));
     $sql = "SELECT id, name, value\n                FROM `s_core_config_elements`\n                WHERE `form_id` = ?";
     $tsExcElementsTemp = $this->db->fetchAll($sql, array($tsExcFormId));
     $tsExcElements = array();
     foreach ($tsExcElementsTemp as $element) {
         $tsExcElements[] = array('id' => $element['id'], 'name' => $element['name'], 'defaultValue' => $element['value']);
     }
     $tsExcValuesTemp = array();
     foreach ($tsExcElements as $element) {
         $sql = "SELECT shop_id,element_id, value\n                    FROM `s_core_config_values`\n                    WHERE `element_id` = ?";
         $tsExcValuesTemp[] = $this->db->fetchAll($sql, array($element['id']));
     }
     //converts the data into a nice array
     $tsExcValues = array();
     foreach ($tsExcElements as $element) {
         foreach ($tsExcValuesTemp as $values) {
             if (empty($values)) {
                 continue;
             }
             foreach ($values as $value) {
                 if ($element['id'] == $value['element_id']) {
                     $tsExcValues[$element['name']][$value['shop_id']] = unserialize($value['value']);
                 }
             }
         }
     }
     return $tsExcValues;
 }
Exemplo n.º 10
0
/**
 * @param Connection $connection
 * @return Connection
 */
function getDbConnection($connection)
{
    $currentVersion = getDbPatcherVersion();
    try {
        $version = $connection->fetchColumn('SELECT db_patcher_version()');
    } catch (DBALException $e) {
        createDbPatcherVersionSqlFunction($connection);
        $connection->executeQuery(<<<SQL
CREATE TABLE db_patcher
(
  id serial NOT NULL,
  "name" text NOT NULL,
  status smallint NOT NULL DEFAULT 0,
  md5 text NOT NULL,
  CONSTRAINT pk_db_patch PRIMARY KEY (id ),
  CONSTRAINT ak_key_2_db_patch UNIQUE ("name")
)
SQL
);
        $version = $currentVersion;
    }
    if (version_compare($currentVersion, $version) > 0) {
        updateDbPatcherDatabase($connection, $version);
        createDbPatcherVersionSqlFunction($connection);
    }
    return $connection;
}
Exemplo n.º 11
0
 /**
  * Returns the total number of executed migration versions
  *
  * @return integer
  */
 public function getNumberOfExecutedMigrations()
 {
     $this->connect();
     $this->createMigrationTable();
     $result = $this->connection->fetchColumn("SELECT COUNT(" . $this->migrationsColumnName . ") FROM " . $this->migrationsTableName);
     return $result !== false ? $result : 0;
 }
Exemplo n.º 12
0
 /**
  * Update entity in the database (partial data is supported).
  *
  * @param \Lokhman\Silex\ARM\AbstractEntity $entity
  *
  * @throws \Exception
  * @return integer
  *         Number of affected rows
  */
 public function update(AbstractEntity $entity)
 {
     $this->assert($entity);
     // check if primary key is defined and is not NULL
     $primary = $this->metadata->getPrimary();
     if (!isset($entity[$primary])) {
         self::raise('Primary key is required to update the entity.');
     }
     try {
         $this->db->beginTransaction();
         // pre-update event
         $this->preUpdate($entity);
         // validate entity
         $this->validateUpdate($entity);
         // if position column exists
         if ($this->metadata->hasPosition()) {
             $this->positionUpdate($entity);
         }
         // get raw data from entity
         $data = AbstractEntity::raw($entity);
         $id = $data[$primary];
         unset($data[$primary]);
         if ($this->translate) {
             $sql = 'SELECT COUNT(*) FROM ' . $this->app['arm.trans'] . ' WHERE _table = :_table AND _key = :_key AND ' . '_column = :_column AND _locale = :_locale';
             // for each translatable column in schema
             foreach ($this->metadata->getTrans() as $column) {
                 // if no column presented in the data
                 if (!array_key_exists($column, $data)) {
                     continue;
                 }
                 $trans = ['_table' => $this->table, '_key' => $id, '_column' => $column, '_locale' => $this->locale];
                 if ($data[$column] === null) {
                     // if column exists but is NULL: delete translation
                     $this->db->delete($this->app['arm.trans'], $trans);
                 } elseif ($this->db->fetchColumn($sql, $trans) > 0) {
                     // if translation exists: update translation
                     $this->db->update($this->app['arm.trans'], ['_content' => $data[$column]], $trans);
                 } else {
                     // if translation doesn't exist: insert translation
                     $this->db->insert($this->app['arm.trans'], $trans + ['_content' => $data[$column]]);
                 }
                 // remove value from actual data
                 unset($data[$column]);
             }
         }
         if ($data) {
             // update entity data if there is anything to update
             $result = $this->db->update($this->table, $data, [$primary => $id]);
         }
         $this->db->commit();
         // post-update event
         $this->postUpdate($entity);
     } catch (\Exception $ex) {
         $this->unlink($entity);
         $this->rollback();
         throw $ex;
     }
     return $result;
 }
Exemplo n.º 13
0
 /**
  * Returns the number of rows in the given table. You can specify an
  * optional where clause to return a subset of the table.
  *
  * @param string $tableName
  * @param string $whereClause
  * @param int
  */
 public function getRowCount($tableName, $whereClause = NULL)
 {
     $sql = "SELECT count(*) FROM " . $tableName;
     if ($whereClause !== null) {
         $sql .= " WHERE " . $whereClause;
     }
     return $this->_conn->fetchColumn($sql);
 }
Exemplo n.º 14
0
 public function save(Connection $conn)
 {
     $exists = $conn->fetchColumn('SELECT `id` FROM `' . ForumTables::FORUM_ROOT_TBL . '` WHERE `id` = :id', [':id' => $this->id]);
     if (!empty($exists)) {
         $conn->insert(ForumTables::FORUM_ROOT_TBL, ['id' => $id, 'name' => $name]);
     } else {
         $conn->update(ForumTables::FORUM_ROOT_TBL, ['id' => $id, 'name' => $name]);
     }
 }
Exemplo n.º 15
0
 /**
  * Checks whether the given managed entity exists in the database.
  *
  * @param object $entity
  * @return boolean TRUE if the entity exists in the database, FALSE otherwise.
  */
 public function exists($entity, array $extraConditions = array())
 {
     $criteria = $this->_class->getIdentifierValues($entity);
     if ($extraConditions) {
         $criteria = array_merge($criteria, $extraConditions);
     }
     $sql = 'SELECT 1 ' . $this->getLockTablesSql() . ' WHERE ' . $this->_getSelectConditionSQL($criteria);
     return (bool) $this->_conn->fetchColumn($sql, array_values($criteria));
 }
Exemplo n.º 16
0
 /**
  * Checks whether the given managed entity exists in the database.
  *
  * @param object $entity
  * @return boolean TRUE if the entity exists in the database, FALSE otherwise.
  */
 public function exists($entity, array $extraConditions = array())
 {
     $criteria = $this->_class->getIdentifierValues($entity);
     if ($extraConditions) {
         $criteria = array_merge($criteria, $extraConditions);
     }
     $sql = 'SELECT 1 FROM ' . $this->_class->getQuotedTableName($this->_platform) . ' ' . $this->_getSQLTableAlias($this->_class->name) . ' WHERE ' . $this->_getSelectConditionSQL($criteria);
     return (bool) $this->_conn->fetchColumn($sql, array_values($criteria));
 }
 /**
  * Validate a refresh token
  *
  * @param  string   $refreshToken The access token
  * @param  string   $clientId     The client ID
  * @return int|bool               The ID of the access token the refresh token is linked to (or false if invalid)
  */
 public function validateRefreshToken($refreshToken, $clientId)
 {
     $sql = 'SELECT session_access_token_id
       FROM `oauth_session_refresh_tokens`
       WHERE refresh_token = :refreshToken
       AND refresh_token_expires >= :timeNow
       AND client_id = :clientId';
     $params = array('refreshToken' => $refreshToken, 'timeNow' => time(), 'clientId' => $clientId);
     return $this->conn->fetchColumn($sql, $params);
 }
Exemplo n.º 18
0
 /**
  * {@inheritdoc}
  */
 public function update()
 {
     $version = 0;
     if ($this->connection->getSchemaManager()->tablesExist(['vbee_version'])) {
         $version = $this->connection->fetchColumn('SELECT version FROM vbee_version');
     }
     switch ($version) {
         case 0:
             try {
                 $this->migrationVersion1();
                 $this->upgradeVersion(1);
             } catch (DBALException $e) {
                 // Log error
             }
             break;
         case 1:
             break;
     }
 }
Exemplo n.º 19
0
 public function countRoutes()
 {
     $this->transaction->requestTransaction();
     try {
         return $this->conn->fetchColumn('SELECT COUNT(r.`id`) ' . 'FROM `' . EdkTables::ROUTE_TBL . '` r ' . 'INNER JOIN `' . CoreTables::AREA_TBL . '` a ON r.`areaId` = a.`id` ' . $this->createWhereClause(), [':itemId' => $this->root->getId()]);
     } catch (Exception $ex) {
         $this->transaction->requestRollback();
         throw $ex;
     }
 }
Exemplo n.º 20
0
 /**
  * This function retrieves the default version value which was created
  * by the DBMS INSERT statement. The value is assigned back in to the 
  * $entity versionField property.
  *
  * @return void
  */
 protected function _assignDefaultVersionValue($class, $entity, $id)
 {
     $versionField = $this->_class->versionField;
     $identifier = $this->_class->getIdentifierColumnNames();
     $versionFieldColumnName = $this->_class->getColumnName($versionField);
     //FIXME: Order with composite keys might not be correct
     $sql = "SELECT " . $versionFieldColumnName . " FROM " . $class->getQuotedTableName($this->_platform) . " WHERE " . implode(' = ? AND ', $identifier) . " = ?";
     $value = $this->_conn->fetchColumn($sql, array_values((array) $id));
     $this->_class->setFieldValue($entity, $versionField, $value);
 }
Exemplo n.º 21
0
 /**
  * Creates and inserts into the database the password recovery request.
  * 
  * @param User $user The user that requests password recovery
  * @param string $ip Current IP address of the request
  * @return PasswordRecoveryRequest
  */
 public function createPasswordRecoveryRequest(User $user, $ip)
 {
     $request = PasswordRecoveryRequest::create($user, $ip, time());
     $id = $this->conn->fetchColumn('SELECT `id` FROM `' . CoreTables::PASSWORD_RECOVERY_TBL . '` WHERE `requestIp` = :ip AND `requestTime` > :minTime', [':ip' => $request->getRequestIp(), ':minTime' => time() - PasswordRecoveryRequest::REQUEST_INTERVAL_TIME]);
     if (!empty($id)) {
         throw new PasswordRecoveryException('Error while saving the password recovery request.');
     }
     $request->insert($this->conn);
     return $request;
 }
 public function countParticipants()
 {
     $this->transaction->requestTransaction();
     try {
         return $this->conn->fetchColumn('SELECT SUM(s.`participantNum`) + SUM(s.`externalParticipantNum`) ' . 'FROM `' . EdkTables::REGISTRATION_SETTINGS_TBL . '` s ' . 'INNER JOIN `' . EdkTables::ROUTE_TBL . '` r ON r.`id` = s.`routeId` ' . 'INNER JOIN `' . CoreTables::AREA_TBL . '` a ON r.`areaId` = a.`id` ' . $this->createWhereClause(), [':itemId' => $this->root->getId()]);
     } catch (Exception $ex) {
         $this->transaction->requestRollback();
         throw $ex;
     }
 }
Exemplo n.º 23
0
 public function insert(\Doctrine\DBAL\Connection $db)
 {
     $jobDuplicate = $db->fetchColumn('select jobid from jobs where (dateadded=? and sourceid=? and applyurl=?) or (position=? and companyid=?)', [(string) $this->dateadded, (int) $this->sourceid, (string) trim($this->applyurl), (string) trim($this->position), (int) $this->company->id]);
     if ($jobDuplicate) {
         return false;
     }
     $this->description = $string = preg_replace('/(<br\\/>){2,}/', '<br/>', html_entity_decode(trim(strip_tags(str_replace(['<div>', '</div>', '<br />', "\n\n"], ['', "<br/>", "<br/>", "<br/>"], $this->description), '<b><strong><ul><li><br><br/><br />'))));
     $db->insert('jobs', ['applyurl' => trim($this->applyurl), 'position' => trim($this->position), 'dateadded' => $this->dateadded, 'description' => trim($this->description), 'sourceid' => $this->sourceid, 'companyid' => $this->company->id]);
     $this->jobid = $db->lastInsertId();
     return $this->jobid;
 }
Exemplo n.º 24
0
 /**
  * Fetch the registry by page root ID
  *
  * @param int $rootPageId
  *
  * @return array
  *
  * @throws \InvalidArgumentException
  */
 private function fetchRegistryByPageRootId($rootPageId)
 {
     $associatedRegistry = $this->db->fetchColumn('SELECT cfg_link_registry FROM tl_page WHERE id=?', [$rootPageId]);
     if ($associatedRegistry === false) {
         throw new \InvalidArgumentException(sprintf('There is no link registry associated with root page ID %s', $rootPageId));
     }
     $registry = $this->db->fetchAssoc('SELECT * FROM tl_cfg_link_registry WHERE id=?', [$associatedRegistry]);
     if ($registry === false) {
         throw new \InvalidArgumentException(sprintf('There is no link registry with ID %s', $associatedRegistry));
     }
     return $registry;
 }
Exemplo n.º 25
0
 public function insert(\Doctrine\DBAL\Connection $db)
 {
     $duplicateId = $db->fetchColumn('select companyid from companies where name=?', [(string) $this->name]);
     if ($duplicateId) {
         $this->id = $duplicateId;
         return $duplicateId;
     }
     $company = ['name' => $this->name, 'dateadded' => date('Y-m-d H:i:s'), 'logo' => $this->logo, 'twitter' => $this->twitter, 'url' => $this->url];
     $db->insert('companies', $company);
     $this->id = $db->lastInsertId();
     return $this->id;
 }
 /**
  * Insert a new User instance into the database.
  *
  * @param User $user
  *
  * Contains change jasongrimes' library:
  * Problem: the postgres PSO->lastInsertId() requires an additional parameter (which will depend on the db)
  * Solution: Use INSERT INTO RETURNING syntax
  */
 public function insert(User $user)
 {
     $this->dispatcher->dispatch(UserEvents::BEFORE_INSERT, new UserEvent($user));
     $sql = 'INSERT INTO ' . $this->conn->quoteIdentifier($this->userTableName) . '
         (' . $this->getUserColumns('email') . ', ' . $this->getUserColumns('password') . ', ' . $this->getUserColumns('salt') . ', ' . $this->getUserColumns('name') . ', ' . $this->getUserColumns('roles') . ', ' . $this->getUserColumns('time_created') . ', ' . $this->getUserColumns('username') . ', ' . $this->getUserColumns('isEnabled') . ', ' . $this->getUserColumns('confirmationToken') . ', ' . $this->getUserColumns('timePasswordResetRequested') . ')
         VALUES (:email, :password, :salt, :name, :roles, :timeCreated, :username, :isEnabled, :confirmationToken, :timePasswordResetRequested) RETURNING ' . $this->getUserColumns('id');
     $params = array('email' => $user->getEmail(), 'password' => $user->getPassword(), 'salt' => $user->getSalt(), 'name' => $user->getName(), 'roles' => implode(',', $user->getRoles()), 'timeCreated' => $user->getTimeCreated(), 'username' => $user->getRealUsername(), 'isEnabled' => $user->isEnabled(), 'confirmationToken' => $user->getConfirmationToken(), 'timePasswordResetRequested' => $user->getTimePasswordResetRequested());
     $userid = $this->conn->fetchColumn($sql, $params);
     $user->setId($userid);
     $this->saveUserCustomFields($user);
     $this->identityMap[$user->getId()] = $user;
     $this->dispatcher->dispatch(UserEvents::AFTER_INSERT, new UserEvent($user));
 }
Exemplo n.º 27
0
 /**
  * Checks whether the given managed entity exists in the database.
  *
  * @param object $entity
  * @return boolean TRUE if the entity exists in the database, FALSE otherwise.
  */
 public function exists($entity, array $extraConditions = array())
 {
     $criteria = $this->_class->getIdentifierValues($entity);
     if ($extraConditions) {
         $criteria = array_merge($criteria, $extraConditions);
     }
     $alias = $this->_getSQLTableAlias($this->_class->name);
     $sql = 'SELECT 1 ' . $this->getLockTablesSql() . ' WHERE ' . $this->_getSelectConditionSQL($criteria);
     if ($filterSql = $this->generateFilterConditionSQL($this->_class, $alias)) {
         $sql .= ' AND ' . $filterSql;
     }
     list($params, $types) = $this->expandParameters($criteria);
     return (bool) $this->_conn->fetchColumn($sql, $params);
 }
 /**
  * {@inheritdoc}
  */
 public function execute(LoggerInterface $logger)
 {
     // update field itself
     $sql = "UPDATE oro_entity_config_index_value\n            SET value = ?\n            WHERE\n                entity_id = (SELECT id FROM oro_entity_config WHERE class_name = ? LIMIT 1) AND\n                field_id IS NULL AND\n                scope = ? AND\n                code = ?\n            ";
     $parameters = [$this->value, $this->entityName, $this->scope, $this->code];
     $statement = $this->connection->prepare($sql);
     $statement->execute($parameters);
     $this->logQuery($logger, $sql, $parameters);
     $logger->debug($sql);
     // update entity config cached data
     $sql = 'SELECT data FROM oro_entity_config WHERE class_name = ? LIMIT 1';
     $parameters = [$this->entityName];
     $data = $this->connection->fetchColumn($sql, $parameters);
     $this->logQuery($logger, $sql, $parameters);
     $data = $data ? $this->connection->convertToPHPValue($data, Type::TARRAY) : [];
     $data[$this->scope][$this->code] = $this->value;
     $data = $this->connection->convertToDatabaseValue($data, Type::TARRAY);
     $sql = 'UPDATE oro_entity_config SET data = ? WHERE class_name = ?';
     $parameters = [$data, $this->entityName];
     $statement = $this->connection->prepare($sql);
     $statement->execute($parameters);
     $this->logQuery($logger, $sql, $parameters);
 }
Exemplo n.º 29
0
 /**
  * Return all information of a route name which are save in the cache otherwise in the database.
  *
  * @param string  $route         The route name
  * @return array
  * @access public
  * 
  * @author Etienne de Longeaux <*****@*****.**>
  * @since 2012-02-27
  */
 public function getRoute($route)
 {
     // values can potentially be large, so we hash them and prevent collisions
     $hashKey = sha1($route);
     $cacheKey = "pi_route__" . $hashKey;
     $RouteValues = $this->cache->fetch($cacheKey);
     if ($RouteValues && isset($RouteValues[$hashKey])) {
         //print_r($RouteValues[$hashKey]);exit;
         return $RouteValues[$hashKey];
     }
     $value = array();
     if ($RouteValues = $this->connection->fetchColumn("SELECT id FROM pi_routing WHERE route = ?", array($route))) {
         return $RouteValues;
     } else {
         return null;
     }
 }
Exemplo n.º 30
0
 private function isAllowedForGroup(Entity $entity, MembershipEntityInterface $who, $editable = false)
 {
     switch ($entity->getType()) {
         case 'Project':
             return false;
         case 'Group':
             if (!$editable || $this->settings->get(MilestoneSettings::GROUP_CAN_UPDATE_OWN_PROGRESS)->getValue()) {
                 return $who->getEntity()->getId() == $entity->getId();
             }
             return false;
         case 'Area':
             if (!$editable || $this->settings->get(MilestoneSettings::GROUP_CAN_UPDATE_AREA_PROGRESS)->getValue()) {
                 $pid = $this->conn->fetchColumn('SELECT `groupId` FROM `' . CoreTables::AREA_TBL . '` WHERE `entityId` = :id', [':id' => $entity->getId()]);
                 return $pid == $who->getId();
             }
             return false;
     }
     return false;
 }