Exemple #1
0
 /**
  * Implement the select-delete-insert
  * This is in SQLResource because it's not generic, file resource
  * will just overwrite existing record, but we can't insert if the
  * row is present
  * @param Record $record
  */
 protected function doRegister($record)
 {
     $data = $record->toAssoc();
     $data['lastModified'] = time();
     $data['content'] = serialize($data['content']);
     // This already deletes the stale records from DB
     $r = $this->doRetrieve($record->getKey());
     if ($r instanceof Record) {
         $this->doDelete($record->getKey());
     }
     $k = $this->dbc->insert($data);
     if ($k !== false) {
         return $record->getKey();
     }
     return false;
 }
Exemple #2
0
 /**
  * Implementation specific low level write operation
  *
  * @param Record $record
  * @return boolean
  */
 protected function doRegister($record)
 {
     $key = $record->getKey();
     // Dump to file
     $file_path = $this->key2filepath($key);
     // Added support for multi-dir scalable file storage
     if (!file_exists(dirname($file_path))) {
         mkdir(dirname($file_path), 0777, true);
     }
     // Mutex lock for writes
     if (!file_put_contents($file_path, serialize($record), LOCK_EX)) {
         self::$log->error("Unable to write record to file: " . $key);
         return false;
     }
     return true;
 }