Exemple #1
0
 /**
  * Inserts/Updates a permission in the access list
  *
  * @param  string                 $roleName
  * @param  string                 $resourceName
  * @param  string                 $accessName
  * @param  integer                $action
  * @return boolean
  * @throws \Phalcon\Acl\Exception
  */
 protected function insertOrUpdateAccess($roleName, $resourceName, $accessName, $action)
 {
     /**
      * Check if the access is valid in the resource
      */
     $sql = "SELECT COUNT(*) FROM {$this->resourcesAccesses} WHERE resources_name = ? AND access_name = ?";
     $exists = $this->connection->fetchOne($sql, null, [$resourceName, $accessName]);
     if (!$exists[0]) {
         throw new Exception("Access '{$accessName}' does not exist in resource '{$resourceName}' in ACL");
     }
     /**
      * Update the access in access_list
      */
     $sql = "SELECT COUNT(*) FROM {$this->accessList} " . " WHERE roles_name = ? AND resources_name = ? AND access_name = ?";
     $exists = $this->connection->fetchOne($sql, null, [$roleName, $resourceName, $accessName]);
     if (!$exists[0]) {
         $sql = "INSERT INTO {$this->accessList} VALUES (?, ?, ?, ?)";
         $params = [$roleName, $resourceName, $accessName, $action];
     } else {
         $sql = "UPDATE {$this->accessList} SET allowed = ? " . "WHERE roles_name = ? AND resources_name = ? AND access_name = ?";
         $params = [$action, $roleName, $resourceName, $accessName];
     }
     $this->connection->execute($sql, $params);
     /**
      * Update the access '*' in access_list
      */
     $sql = "SELECT COUNT(*) FROM {$this->accessList} " . "WHERE roles_name = ? AND resources_name = ? AND access_name = ?";
     $exists = $this->connection->fetchOne($sql, null, [$roleName, $resourceName, '*']);
     if (!$exists[0]) {
         $sql = "INSERT INTO {$this->accessList} VALUES (?, ?, ?, ?)";
         $this->connection->execute($sql, [$roleName, $resourceName, '*', $this->_defaultAccess]);
     }
     return true;
 }
 public static function setCurrentVersion($lastVersion, $currentVersion)
 {
     if (is_null(self::$_connection)) {
         self::connSetup(self::$_config->get('database'));
     }
     if (!is_null(self::$_config->get('migrationsLog')) && 'database' == self::$_config->get('migrationsLog')) {
         self::$_connection->execute('UPDATE `phalcon_migrations` SET `version`="' . (string) $currentVersion . '" WHERE `version`="' . (string) $lastVersion . '" LIMIT 1;');
     } else {
         file_put_contents(self::$_migrationFid, (string) $currentVersion);
     }
 }
Exemple #3
0
 /**
  * {@inheritdoc}
  *
  * @return boolean
  */
 public function destroy($session_id = null)
 {
     if (!$this->isStarted()) {
         return true;
     }
     if (is_null($session_id)) {
         $session_id = $this->getId();
     }
     $this->_started = false;
     $options = $this->getOptions();
     $result = $this->connection->execute(sprintf('DELETE FROM %s WHERE %s = ?', $this->connection->escapeIdentifier($options['table']), $this->connection->escapeIdentifier($options['column_session_id'])), [$session_id]);
     return $result && session_destroy();
 }
Exemple #4
0
 /**
  * {@inheritdoc}
  *
  * @return bool
  */
 public function flush()
 {
     $this->db->execute("DELETE FROM {$this->table}");
     return true;
 }
Exemple #5
0
 /**
  * Writes the log to the file itself
  *
  * @param string  $message
  * @param integer $type
  * @param integer $time
  * @param array   $context
  * @return bool
  */
 public function logInternal($message, $type, $time, $context = [])
 {
     return $this->db->execute('INSERT INTO ' . $this->options['table'] . ' VALUES (null, ?, ?, ?, ?)', [$this->name, $type, $message, $time], [Column::BIND_PARAM_STR, Column::BIND_PARAM_INT, Column::BIND_PARAM_STR, Column::BIND_PARAM_INT]);
 }
Exemple #6
0
 /**
  * {@inheritdoc}
  *
  * @return boolean
  */
 public function flush()
 {
     $this->db->execute('DELETE FROM ' . $this->table);
     return true;
 }
Exemple #7
0
 /**
  * {@inheritdoc}
  * @param  integer $maxlifetime
  *
  * @return boolean
  */
 public function gc($maxlifetime)
 {
     $options = $this->getOptions();
     return $this->connection->execute(sprintf('DELETE FROM %s WHERE COALESCE(%s, %s) + %d < ?', $this->connection->escapeIdentifier($options['table']), $this->connection->escapeIdentifier($options['column_modified_at']), $this->connection->escapeIdentifier($options['column_created_at']), $maxlifetime), [time()]);
 }