setCache() public method

Set the cache component.
public setCache ( Desarrolla2\Cache\Adapter\AdapterInterface $adapter, integer $ttl = 3600 )
$adapter Desarrolla2\Cache\Adapter\AdapterInterface See https://github.com/desarrolla2/Cache
$ttl integer Time to live in seconds
Esempio n. 1
0
<?php

require __DIR__ . '/../../../vendor/autoload.php';
use VisualAppeal\AutoUpdate;
$update = new AutoUpdate(__DIR__ . '/temp', __DIR__ . '/../', 60);
$update->setCurrentVersion('0.1.0');
$update->setUpdateUrl('http://php-auto-update.app/server');
//Replace with your server update directory
// Optional:
$update->addLogHandler(new Monolog\Handler\StreamHandler(__DIR__ . '/update.log'));
$update->setCache(new Desarrolla2\Cache\Adapter\File(__DIR__ . '/cache'), 3600);
//Check for a new update
if ($update->checkUpdate() === false) {
    die('Could not check for updates! See log file for details.');
}
if ($update->newVersionAvailable()) {
    //Install new update
    echo 'New Version: ' . $update->getLatestVersion() . '<br>';
    echo 'Installing Updates: <br>';
    echo '<pre>';
    var_dump(array_map(function ($version) {
        return (string) $version;
    }, $update->getVersionsToUpdate()));
    echo '</pre>';
    // This call will only simulate an update.
    // Set the first argument (simulate) to "false" to install the update
    // i.e. $update->update(false);
    $result = $update->update();
    if ($result === true) {
        echo 'Update simulation successful<br>';
    } else {
Esempio n. 2
0
 function update($name = 'admin')
 {
     require APPPATH . 'third_party/update/vierbergenlars/SemVer/expression.php';
     require APPPATH . 'third_party/update/vierbergenlars/SemVer/version.php';
     require APPPATH . 'third_party/update/Psr/Log/LoggerInterface.php';
     require APPPATH . 'third_party/update/Monolog/Logger.php';
     require APPPATH . 'third_party/update/Monolog/Formatter/FormatterInterface.php';
     require APPPATH . 'third_party/update/Monolog/Formatter/NormalizerFormatter.php';
     require APPPATH . 'third_party/update/Monolog/Formatter/LineFormatter.php';
     require APPPATH . 'third_party/update/Monolog/Handler/HandlerInterface.php';
     require APPPATH . 'third_party/update/Monolog/Handler/AbstractHandler.php';
     require APPPATH . 'third_party/update/Monolog/Handler/AbstractProcessingHandler.php';
     require APPPATH . 'third_party/update/Monolog/Handler/StreamHandler.php';
     require APPPATH . 'third_party/update/Monolog/Handler/NullHandler.php';
     require APPPATH . 'third_party/update/Desarrolla2/CacheInterface.php';
     require APPPATH . 'third_party/update/Desarrolla2/Adapter/AdapterInterface.php';
     require APPPATH . 'third_party/update/Desarrolla2/Adapter/AbstractAdapter.php';
     require APPPATH . 'third_party/update/Desarrolla2/Adapter/NotCache.php';
     require APPPATH . 'third_party/update/Desarrolla2/Adapter/File.php';
     require APPPATH . 'third_party/update/Desarrolla2/Cache.php';
     require APPPATH . 'third_party/update/AutoUpdate.php';
     // Config
     $this->lang->load('system/sys_config', $this->Lang);
     if ($name == 'admin') {
         $RootDir = './';
         $UpdateUrl = 'http://www.ksphp.com/update/admin';
         $Cache = 'update/cache_admin';
         $LogFile = 'update/update_admin.log';
         $VersionName = 'version_admin';
         $Version = $this->config->config[$VersionName];
         $data['Name'] = $name;
         $data['Title'] = $this->lang->line('sys_config_admin');
     } elseif ($name == 'themes') {
         $RootDir = '../themes/';
         $UpdateUrl = 'http://www.ksphp.com/update/themes';
         $Cache = 'update/cache_themes';
         $LogFile = 'update/update_themes.log';
         $VersionName = 'version_themes';
         $Version = $this->config->config[$VersionName];
         $data['Name'] = $name;
         $data['Title'] = $this->lang->line('sys_config_themes');
     } elseif ($name == 'webmis') {
         $RootDir = '../webmis/';
         $UpdateUrl = 'http://www.ksphp.com/update/webmis';
         $Cache = 'update/cache_webmis';
         $LogFile = 'update/update_webmis.log';
         $VersionName = 'version_webmis';
         $Version = $this->config->config[$VersionName];
         $data['Name'] = $name;
         $data['Title'] = $this->lang->line('sys_config_webmis');
     } elseif ($name == 'CodeIgniter') {
         $RootDir = '../system/';
         $UpdateUrl = 'http://www.ksphp.com/update/CodeIgniter';
         $Cache = 'update/cache_CodeIgniter';
         $LogFile = 'update/update_CodeIgniter.log';
         $VersionName = 'version_CodeIgniter';
         $Version = $this->config->config[$VersionName];
         $data['Name'] = $name;
         $data['Title'] = $this->lang->line('sys_config_CodeIgniter');
     }
     $update = new AutoUpdate('update/temp', $RootDir, 60);
     $update->setCurrentVersion($Version);
     $update->setUpdateUrl($UpdateUrl);
     $update->addLogHandler(new Monolog\Handler\StreamHandler($LogFile));
     $update->setCache(new Desarrolla2\Cache\Adapter\File($Cache), 3600);
     // Check for a new update
     if ($update->checkUpdate() === false) {
         // die('Could not check for updates! See log file for details.');
         $data['checkUpdate'] = '<span class="red"><b>' . $this->lang->line('sys_config_update_nofind') . '</b></span>';
     } else {
         if ($update->newVersionAvailable()) {
             // var_dump(array_map(function($version) {return (string) $version;}, $update->getVersionsToUpdate()));
             $data['checkUpdate'] = '-> <b style="font-size: 14px; color: #666;">' . $update->getLatestVersion() . '</b> <input type="submit" id="editSub" name="update" value="' . $this->lang->line('sys_config_update_sub') . '" />';
         } else {
             $data['checkUpdate'] = '<span class="green"><b>' . $this->lang->line('sys_config_update_new') . '</b></span>';
         }
     }
     // Update
     $sub = $this->input->post('update');
     $data['Msg'] = '';
     if (isset($sub)) {
         $result = $update->update();
         if ($result === true) {
             $result = $this->_Cinfig(array($VersionName => $update->getLatestVersion()));
             $data['Msg'] = '<span class="green"><b>' . $this->lang->line('sys_config_update_suc') . '</b></span>';
             redirect('sys_config/update/' . $name);
         } else {
             $data['Msg'] = '<span class="red"><b>' . $this->lang->line('sys_config_update_err') . ' : ' . $result . '</b></span>';
             // if ($result = AutoUpdate::ERROR_SIMULATE) {var_dump($update->getSimulationResults());}
         }
     }
     // View
     $this->load->library('inc');
     $data['LoadJS'] = array('system/sys_config.js');
     $data['Log'] = nl2br(file_get_contents($LogFile));
     $data['LogFile'] = str_replace('./', '', $LogFile);
     $data['VersionName'] = $VersionName;
     $data['Menus'] = $this->inc->getMenuAdmin($this);
     $this->inc->adminView($this, 'system/config/update', $data);
 }