Exemple #1
0
 /**
  * @vcr utils#checkCurrentVersion
  */
 public function testCheckForUpdate()
 {
     $log_file = getLogFileName();
     setOutputDestination($log_file);
     $cache = new FileCache();
     $cache->putData('latest_release', ['check_date' => strtotime('8 days ago')]);
     Utils\checkForUpdate(getLogger());
     $file_contents = explode("\n", file_get_contents($log_file));
     $this->assertFalse(strpos(array_pop($file_contents), 'An update to Terminus is available.'));
     resetOutputDestination($log_file);
 }
Exemple #2
0
/**
 * Checks for new versions of Terminus once per week and saves to cache
 *
 * @param Logger $logger Logger to use to report result of check
 * @return void
 */
function checkForUpdate($logger)
{
    $cache = new FileCache();
    $cache_data = $cache->getData('latest_release', ['decode_array' => true]);
    if (!$cache_data || (int) $cache_data['check_date'] < (int) strtotime('-7 days')) {
        try {
            $current_version = checkCurrentVersion();
            if (version_compare($current_version, TERMINUS_VERSION, '>')) {
                $logger->info('An update to Terminus is available. Please update to {version}.', ['version' => $current_version]);
            }
        } catch (\Exception $e) {
            $logger->info($e->getMessage());
            $logger->info('Cannot retrieve current Terminus version.');
        }
    }
}
Exemple #3
0
 public function testRemove()
 {
     $file_name = $this->getFileName();
     setOutputDestination($file_name);
     $removed = $this->file_cache->remove($this->test_file_name);
     $this->assertTrue($removed);
     $removed = $this->file_cache->remove($this->test_file_name);
     $this->assertFalse($removed);
 }
Exemple #4
0
 /**
  * Removes a site from the sites cache
  *
  * @param string $sitename Name of site to remove from array
  * @return void
  */
 public function remove($sitename)
 {
     $cache = (array) $this->cache->getData($this->cachekey, array('decode_array' => true));
     unset($cache[$sitename]);
     $this->cache->putData($this->cachekey, $cache);
 }
Exemple #5
0
 /**
  * Saves session data to cache
  *
  * @param array $data Session data to save
  * @return void|bool
  */
 public static function setData($data)
 {
     if (empty($data)) {
         return false;
     }
     $cache = new FileCache();
     $cache->putData('session', $data);
     $session = self::instance();
     $session->set('data', $data);
     foreach ($data as $k => $v) {
         $session->set($k, $v);
     }
     return true;
 }