Exemple #1
0
 /**
  * Update an existing config setting.
  *
  * @param string $config_name The name of the config setting you would
  * 	like to update
  * @param mixed $config_value The value of the config setting
  * @return null
  * @throws \src\db\migration\exception
  */
 public function update($config_name, $config_value)
 {
     if (!isset($this->config[$config_name])) {
         throw new \src\db\migration\exception('CONFIG_NOT_EXIST', $config_name);
     }
     $this->config->set($config_name, $config_value);
 }
Exemple #2
0
 /**
  * Tries to acquire the lock by updating
  * the configuration variable in the database.
  *
  * As a lock may only be held by one process at a time, lock
  * acquisition may fail if another process is holding the lock
  * or if another process obtained the lock but never released it.
  * Locks are forcibly released after a timeout of 1 hour.
  *
  * @return	bool			true if lock was acquired
  *							false otherwise
  */
 public function acquire()
 {
     if ($this->locked) {
         return false;
     }
     if (!isset($this->config[$this->config_name])) {
         $this->config->set($this->config_name, '0', false);
     }
     $lock_value = $this->config[$this->config_name];
     // make sure lock cannot be acquired by multiple processes
     if ($lock_value) {
         // if the other process is running more than an hour already we have to assume it
         // aborted without cleaning the lock
         $time = explode(' ', $lock_value);
         $time = $time[0];
         if ($time + 3600 >= time()) {
             return false;
         }
     }
     $this->unique_id = time() . ' ' . unique_id();
     // try to update the config value, if it was already modified by another
     // process we failed to acquire the lock.
     $this->locked = $this->config->set_atomic($this->config_name, $lock_value, $this->unique_id, false);
     return $this->locked;
 }
Exemple #3
0
 /**
  * Return unique id
  *
  * @param string $extra Additional entropy
  *
  * @return string Unique id
  */
 public function unique_id($extra = 'c')
 {
     static $dss_seeded = false;
     $val = $this->config['rand_seed'] . microtime();
     $val = md5($val);
     $this->config['rand_seed'] = md5($this->config['rand_seed'] . $val . $extra);
     if ($dss_seeded !== true && $this->config['rand_seed_last_update'] < time() - rand(1, 10)) {
         $this->config->set('rand_seed_last_update', time(), true);
         $this->config->set('rand_seed', $this->config['rand_seed'], true);
         $dss_seeded = true;
     }
     return substr($val, 4, 16);
 }
Exemple #4
0
    /**
     * Delete all notifications older than a certain time
     *
     * @param int $timestamp Unix timestamp to delete all notifications that were created before
     * @param bool $only_read True (default) to only prune read notifications
     */
    public function prune_notifications($timestamp, $only_read = true)
    {
        $sql = 'DELETE FROM ' . $this->notifications_table . '
			WHERE notification_time < ' . (int) $timestamp . ($only_read ? ' AND notification_read = 1' : '');
        $this->db->sql_query($sql);
        $this->config->set('read_notification_last_gc', time(), false);
    }
Exemple #5
0
 /**
  * {@inheritDoc}
  */
 public function run()
 {
     // Remove old temporary file (perhaps failed uploads?)
     $last_valid_timestamp = time() - $this->max_file_age;
     try {
         $iterator = new \DirectoryIterator($this->plupload_upload_path);
         foreach ($iterator as $file) {
             if (strpos($file->getBasename(), $this->config['plupload_salt']) !== 0) {
                 // Skip over any non-plupload files.
                 continue;
             }
             if ($file->getMTime() < $last_valid_timestamp) {
                 @unlink($file->getPathname());
             }
         }
     } catch (\UnexpectedValueException $e) {
         add_log('critical', 'LOG_PLUPLOAD_TIDY_FAILED', $this->plupload_upload_path, $e->getMessage(), $e->getTraceAsString());
     }
     $this->config->set('plupload_last_gc', time(), true);
 }
 /**
  * Set config attachment stat values
  *
  * @param $stats array	Array of config key => value pairs to set.
  * @return null
  */
 public function set_attachment_stats($stats)
 {
     foreach ($stats as $key => $value) {
         $this->config->set($key, $value, true);
     }
 }