示例#1
0
 /**
  * Executes the command cache:purge.
  *
  * Purge the cache (including permissions) and increment the asset_version number
  *
  * @param InputInterface  $input  An InputInterface instance
  * @param OutputInterface $output An OutputInterface instance
  *
  * @return null
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $this->config->increment('assets_version', 1);
     $this->cache->purge();
     // Clear permissions
     $this->auth->acl_clear_prefetch();
     src_cache_moderators($this->db, $this->cache, $this->auth);
     $this->log->add('admin', ANONYMOUS, '', 'LOG_PURGE_CACHE', time(), array());
     $output->writeln($this->user->lang('PURGE_CACHE_SUCCESS'));
 }
示例#2
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);
 }
示例#3
0
    /**
     * Creates a configuration container with a default set of values
     *
     * @param \src\db\driver\driver_interface    $db    Database connection
     * @param \src\cache\driver\driver_interface $cache Cache instance
     * @param string                       $table Configuration table name
     */
    public function __construct(\src\db\driver\driver_interface $db, \src\cache\driver\driver_interface $cache, $table)
    {
        $this->db = $db;
        $this->cache = $cache;
        $this->table = $table;
        if (($config = $cache->get('config')) !== false) {
            $sql = 'SELECT config_name, config_value
				FROM ' . $this->table . '
				WHERE is_dynamic = 1';
            $result = $this->db->sql_query($sql);
            while ($row = $this->db->sql_fetchrow($result)) {
                $config[$row['config_name']] = $row['config_value'];
            }
            $this->db->sql_freeresult($result);
        } else {
            $config = $cached_config = array();
            $sql = 'SELECT config_name, config_value, is_dynamic
				FROM ' . $this->table;
            $result = $this->db->sql_query($sql);
            while ($row = $this->db->sql_fetchrow($result)) {
                if (!$row['is_dynamic']) {
                    $cached_config[$row['config_name']] = $row['config_value'];
                }
                $config[$row['config_name']] = $row['config_value'];
            }
            $this->db->sql_freeresult($result);
            $cache->put('config', $cached_config);
        }
        parent::__construct($config);
    }
示例#4
0
 /**
  * Remove an existing config setting.
  *
  * @param string $config_name The name of the config setting you would
  * 	like to remove
  * @return null
  */
 public function remove($config_name)
 {
     if (!isset($this->config[$config_name])) {
         return;
     }
     $this->config->delete($config_name);
 }
示例#5
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);
    }
示例#6
0
 /**
  * Releases the lock.
  *
  * The lock must have been previously obtained, that is, acquire() call
  * was issued and returned true.
  *
  * Note: Attempting to release a lock that is already released,
  * that is, calling release() multiple times, is harmless.
  *
  * @return null
  */
 public function release()
 {
     if ($this->locked) {
         $this->config->set_atomic($this->config_name, $this->unique_id, '0', false);
         $this->locked = false;
     }
 }
示例#7
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);
 }
示例#8
0
 /**
  * Remove post from topic and forum statistics
  *
  * @param $data			array	Contains information from the topics table about given topic
  * @param &$sql_data		array	Populated with the SQL changes, may be empty at call time
  * @return null
  */
 public function remove_post_from_statistic($data, &$sql_data)
 {
     if ($data['post_visibility'] == ITEM_APPROVED) {
         $sql_data[$this->topics_table] = (!empty($sql_data[$this->topics_table]) ? $sql_data[$this->topics_table] . ', ' : '') . 'topic_posts_approved = topic_posts_approved - 1';
         $sql_data[$this->forums_table] = (!empty($sql_data[$this->forums_table]) ? $sql_data[$this->forums_table] . ', ' : '') . 'forum_posts_approved = forum_posts_approved - 1';
         if ($data['post_postcount']) {
             $sql_data[$this->users_table] = (!empty($sql_data[$this->users_table]) ? $sql_data[$this->users_table] . ', ' : '') . 'user_posts = user_posts - 1';
         }
         $this->config->increment('num_posts', -1, false);
     } else {
         if ($data['post_visibility'] == ITEM_UNAPPROVED || $data['post_visibility'] == ITEM_REAPPROVE) {
             $sql_data[FORUMS_TABLE] = ($sql_data[FORUMS_TABLE] ? $sql_data[FORUMS_TABLE] . ', ' : '') . 'forum_posts_unapproved = forum_posts_unapproved - 1';
             $sql_data[TOPICS_TABLE] = ($sql_data[TOPICS_TABLE] ? $sql_data[TOPICS_TABLE] . ', ' : '') . 'topic_posts_unapproved = topic_posts_unapproved - 1';
         } else {
             if ($data['post_visibility'] == ITEM_DELETED) {
                 $sql_data[FORUMS_TABLE] = ($sql_data[FORUMS_TABLE] ? $sql_data[FORUMS_TABLE] . ', ' : '') . 'forum_posts_softdeleted = forum_posts_softdeleted - 1';
                 $sql_data[TOPICS_TABLE] = ($sql_data[TOPICS_TABLE] ? $sql_data[TOPICS_TABLE] . ', ' : '') . 'topic_posts_softdeleted = topic_posts_softdeleted - 1';
             }
         }
     }
 }
示例#9
0
 protected function finalise_update()
 {
     $this->cache->purge();
     $this->config->increment('assets_version', 1);
 }
示例#10
0
 /**
  * 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);
     }
 }