示例#1
0
 /**
  * Set a locale object.
  */
 public function set($string, $bundle = null, $locale = null)
 {
     // Use the last one as default
     if ($locale === null) {
         $locale = end($this->localeChain);
     }
     if ($bundle === null) {
         $bundle = $this->bundle;
     }
     $contents = array(Node::FIELD_COLLECTION => FRAMEWORK_COLLECTION_TRANSLATION, 'identifier' => md5($string), 'value' => $string, 'key' => $bundle, 'locale' => $locale);
     if (empty($contents['locale'])) {
         throw new FrameworkException('Invalid locale specified.');
     }
     return Node::set($contents);
 }
示例#2
0
 public function write(array $record)
 {
     $record[NODE_FIELD_COLLECTION] = $this->collectionName;
     $record['type'] = $record['level_name'];
     $record['subject'] = strtolower("{$record['channel']}.{$record['level_name']}");
     if (isset($record['extra']['action'])) {
         $record['action'] = $record['extra']['action'];
     }
     // Convert datetime to timestamp format
     if (isset($record['datetime'])) {
         $record['timestamp'] = $record['datetime']->format('Y-m-d H:i:s');
     }
     if (empty($record['context'])) {
         unset($record['context']);
     }
     unset($record['level'], $record['channel'], $record['level_name'], $record['extra']['action'], $record['datetime'], $record['formatted']);
     return (bool) Node::set($record);
 }
示例#3
0
 private function setContents()
 {
     $cObj = $this;
     // Trace upwards until root for the object.
     while ($pObj = $cObj->getParentObject()) {
         $cObj = $pObj;
     }
     unset($pObj);
     $confObj = $cObj->getContents();
     $confKey = $cObj->getKey();
     $filter = array(Node::FIELD_COLLECTION => FRAMEWORK_COLLECTION_CONFIGURATION, '@key' => $confKey);
     if (!$confObj) {
         Node::delete($filter);
     } else {
         Node::set($filter + $confObj);
     }
 }
示例#4
0
 /**
  * Saves the current data into database.
  *
  * @param {&array} $result[errors] Array of validation errors.
  *                 $result[success] True on succeed, otherwise not set.
  */
 function save(array &$result = null)
 {
     $this->_isCreate = !$this->identity();
     $errors = array();
     if ($result !== null) {
         $_result =& $result;
     } else {
         $_result = array();
     }
     $this->beforeSave($errors);
     if ($errors) {
         $_result['errors'] = $errors;
         if ($result === null) {
             throw new ValidatdionException('Error thrown during model validation.', 0, $errors);
         }
     } else {
         try {
             // note; Conflicts here. Virutal fields would love to skip nulls, but real fields would not.
             $res = $this->data;
             $res[Node::FIELD_COLLECTION] = self::collectionName();
             $res = Node::set($res);
             if (is_numeric($res)) {
                 $_result['action'] = 'insert';
                 // Primary keys other than auto_increment will return 0
                 if ($res) {
                     $this->identity($res);
                 }
             } else {
                 if ($res) {
                     $_result['action'] = 'update';
                 }
             }
             $_result['success'] = true;
         } catch (\PDOException $e) {
             if ($result === null) {
                 throw $e;
             }
             $_result['error'] = $e->getMessage();
             $_result['success'] = false;
             unset($_result['action']);
         }
         // Load again to reflect database level changes
         if ($_result['success']) {
             $this->load($this->identity());
         }
         $this->afterSave();
     }
     $this->_isCreate = false;
     return $this;
 }
示例#5
0
 /**
  * Generate a one-time authentication token string for additional
  * security for AJAX service calls.
  *
  * Each additional call to this function overwrites the token generated last time.
  *
  * @return One-time token string, or null on invalid session.
  */
 static function generateToken($sid = null)
 {
     $res = static::ensure($sid);
     if ($res !== true) {
         return $res;
     }
     $res =& static::$currentSession;
     $res['token'] = Database::fetchField("SELECT UNHEX(REPLACE(UUID(),'-',''));");
     unset($res['timestamp']);
     if (Node::set($res) === false) {
         return null;
     }
     return util::unpackUuid($res['token']);
 }
示例#6
0
 /**
  * Updates process related info of specified property $name.
  *
  * Note: Updates to real table properties are ignored, as they are requried
  * by the process framework.
  */
 public static function set($name, $value)
 {
     Database::lockTables(FRAMEWORK_COLLECTION_PROCESS, FRAMEWORK_COLLECTION_LOG);
     $res = self::get();
     if (!$res) {
         Database::unlockTables();
         return false;
     }
     $readOnlyFields = ['id', 'command', 'type', 'weight', 'pid', 'timestamp'];
     if (in_array($name, $readOnlyFields)) {
         Database::unlockTables();
         return false;
     }
     if (is_null($value)) {
         unset($res[$name]);
     } else {
         $res[$name] = $value;
     }
     unset($res['timestamp']);
     $ret = Node::set($res);
     Database::unlockTables();
     // Clear data cache
     self::$_processData = null;
     return $ret;
 }