示例#1
0
 public function __construct()
 {
     self::$cache_folder = new Folder(PATH_TO_ROOT . '/cache');
     self::$tpl_cache_folder = new Folder(self::$cache_folder->get_path() . '/tpl');
     self::$css_cache_folder = new Folder(self::$cache_folder->get_path() . '/css');
     self::$syndication_cache_folder = new Folder(self::$cache_folder->get_path() . '/syndication');
 }
 /**
  * Get the instance
  * @return CacheService
  */
 public static function inst()
 {
     if (!self::$instance) {
         self::$instance = new CacheService();
     }
     return self::$instance;
 }
 /**
  * Update the cache on the database
  * @return int The number of new event saved
  */
 public static function updateCache()
 {
     $startTime = microtime(true);
     $lastDate = CacheService::fetchLastDate();
     $events = CacheService::getEvents($lastDate);
     CacheService::putEvents($events);
     $endTime = microtime(true);
     Logger::log("Tempo di fetch dei log:", $endTime - $startTime);
     return count($events);
 }
 public static function translate($l7prot)
 {
     $l7prot = intval($l7prot);
     $protocols = \CacheService::getProcotolCache();
     if ($protocols && array_key_exists($l7prot, $protocols)) {
         return $protocols[$l7prot]->description;
     } else {
         return 'mark:' . $l7prot;
     }
 }
示例#5
0
 /**
  * List files from a project
  *
  */
 public function filelistAction()
 {
     $project = $this->byId($this->_getParam('projectid'), 'Project');
     $client = $this->byId($project->clientid, 'Client');
     $folder = $this->_getParam('folder', '');
     $path = 'Clients/' . $client->title . '/Projects/' . $project->title;
     $projectPath = $path;
     $parent = '';
     if ($folder != null && mb_strlen($folder)) {
         $path = base64_decode($folder);
         $parent = dirname($path);
         if ($path == $projectPath) {
             $parent = '';
         }
     }
     $content = $this->cacheService->get($path);
     if (!$content) {
         $files = array();
         try {
             $files = $this->fileService->listDirectory($path);
         } catch (Exception $e) {
             $this->log->err("Failed loading files from {$path}");
         }
         $this->view->files = $files;
         $this->view->project = $project;
         if ($path == '/') {
             $this->view->base = '';
         } else {
             $this->view->base = trim($path, '/') . '/';
         }
         $this->view->parentPath = $parent;
         $content = $this->view->render('project/file-list.php');
         $this->cacheService->store($path, $content);
     }
     $this->getResponse()->appendBody($content);
 }
 /**
  * Call a URL directly, without it being mapped to a configured web method.
  *
  * This differs from the above in that the caller already knows what
  * URL is trying to be called, so we can bypass the business of mapping
  * arguments all over the place.
  *
  * We still maintain the globalParams for this client though
  *
  * @param $url
  * 			The URL to call
  * @param $args
  * 			Parameters to be passed on the call
  * @return mixed
  */
 public function callUrl($url, $args = array(), $returnType = 'raw', $requestType = 'GET', $cache = 300, $enctype = Zend_Http_Client::ENC_URLENCODED)
 {
     $body = null;
     // use the method params to try caching the results
     // need to add in the baseUrl we're connecting to, and any global params
     // because the cache might be connecting via different users, and the
     // different users will have different sessions. This might need to be
     // tweaked to handle separate user logins at a later point in time
     $cacheKey = md5($url . $requestType . var_export($args, true) . var_export($this->globalParams, true));
     $requestType = isset($methodDetails['method']) ? $methodDetails['method'] : 'GET';
     if (mb_strtolower($requestType) == 'get' && $cache) {
         $body = CacheService::inst()->get($cacheKey);
     }
     if (!$body) {
         $uri = $url;
         $client = $this->getClient($uri);
         $client->setMethod($requestType);
         // set the encoding type
         $client->setEncType($enctype);
         $paramMethod = 'setParameter' . $requestType;
         // make sure to add the alfTicket parameter
         if ($this->globalParams) {
             foreach ($this->globalParams as $key => $value) {
                 $client->{$paramMethod}($key, $value);
             }
         }
         foreach ($args as $index => $pname) {
             $client->{$paramMethod}($index, $pname);
         }
         // request away
         $response = $client->request();
         if ($response->isSuccessful()) {
             $body = $response->getBody();
             if ($cache) {
                 CacheService::inst()->store($cacheKey, $body, $cache);
             }
         } else {
             if ($response->getStatus() == 500) {
                 error_log("Failure: " . $response->getBody());
                 error_log(var_export($client, true));
             }
             throw new FailedRequestException("Failed executing {$url}: " . $response->getMessage() . " for request to {$uri} (" . $client->getUri(true) . ')', $response->getBody());
         }
     }
     // see what we need to do with it
     if (isset($this->returnHandlers[$returnType])) {
         $handler = $this->returnHandlers[$returnType];
         return $handler->handleReturn($body);
     } else {
         return $body;
     }
 }
<?php

require '../base/Config.php';
Config::init();
$service = new ZoneService();
if (isset($_POST["game"]) === false || isset($_POST["type"]) === false || isset($_POST["platform"]) === false) {
    $service->error("zoneinfo", 1);
}
$game = $_POST["game"];
$type = $_POST["type"];
$platform = $_POST["platform"];
if (!is_numeric($game) || !is_numeric($type)) {
    $service->error("zoneinfo", 2);
}
$service->init();
$cache_service = new CacheService();
$cache_service->init();
$file_name = "../bin/cache/zoneinfo_" . $game . "_" . $type . "_" . $platform . ".txt";
$array = $cache_service->getCacheInfo($file_name);
if (null == $array) {
    $array = $service->getZoneInfo($game, $type, $platform);
    if (count($array)) {
        $cache_service->setCacheInfo($file_name, $array);
    }
}
if (count($array)) {
    $service->response(array("zoneinfo" => $array));
} else {
    $service->error("zoneinfo", 3);
}
 /**
  * Update the cache
  * @return int Return the number of new events
  */
 public static function updateCache()
 {
     return CacheService::updateCache();
 }
    /**
     * Gets an object based on its ID
     * 
     * @param String $id
     * @return array
     */
    public function getObject($id)
    {
        $cacheKey = md5($this->url . '|getObject|' . $id . '|' . $this->username);
        $data = CacheService::inst()->get($cacheKey);
        if (!$data) {
            $id = $this->getCompoundId($id);
            if (!$id->id) {
                // just the list
                $lists = $this->getLists();
                return isset($lists[$id->listId]) ? $lists[$id->listId] : null;
            }
            $xml = <<<XML
\t\t\t<Query>
\t\t\t   <Where>
\t\t\t      <Eq>
\t\t\t         <FieldRef Name="ID" />
\t\t\t         <Value Type="Counter">{$id->id}</Value>
\t\t\t      </Eq>
\t\t\t   </Where>
\t\t\t</Query>
XML;
            $searchQueryArgs = array('listName' => $id->listId, 'queryOptions' => array(self::SEARCH_QUERY_OPTIONS), 'query' => array($xml));
            $result = $this->getClient()->call('GetListItems', $searchQueryArgs);
            // This result SHOULD be of the form
            /*Array
            		(
            		    [GetListItemsResult] => Array
            		        (
            		            [listitems] => Array
            		                (
            		                    [data] => Array
            		                        (
            		                            [row] => Array*/
            $obj = null;
            if (isset($result['GetListItemsResult']['listitems']['data']['row'])) {
                $obj = $this->sanitiseObject($result['GetListItemsResult']['listitems']['data']['row'], $id->listId);
                // set the compound ID
            }
            CacheService::inst()->store($cacheKey, $obj);
            return $obj;
        }
        return $data;
    }
 public function save($context = "superuser")
 {
     $this->_save($context);
     CacheService::save("shared", "pydio:user:" . $this->getId(), $this);
 }
示例#11
0
 /**
  * See static method
  * @param $repoId
  * @return int
  */
 public function deleteRepositoryInst($repoId)
 {
     AJXP_Controller::applyHook("workspace.before_delete", array($repoId));
     $confStorage = self::getConfStorageImpl();
     $shares = $confStorage->listRepositoriesWithCriteria(array("parent_uuid" => $repoId));
     $toDelete = array();
     foreach ($shares as $share) {
         $toDelete[] = $share->getId();
     }
     $res = $confStorage->deleteRepository($repoId);
     if ($res == -1) {
         return $res;
     }
     foreach ($toDelete as $deleteId) {
         $this->deleteRepositoryInst($deleteId);
     }
     AJXP_Controller::applyHook("workspace.after_delete", array($repoId));
     AJXP_Logger::info(__CLASS__, "Delete Repository", array("repo_id" => $repoId));
     $this->invalidateLoadedRepositories();
     CacheService::delete(AJXP_CACHE_SERVICE_NS_SHARED, "repository:" . $repoId);
     return 0;
 }
 /**
  * Remove a cache key.
  *
  * @param string $key Key to remove.
  */
 public function remove($key)
 {
     \CacheService::delete(AJXP_CACHE_SERVICE_NS_NODES, $key);
 }
 public function clearCacheByNS($actionName, $httpVars, $fileVars)
 {
     $ns = AJXP_Utils::sanitize($httpVars["namespace"], AJXP_SANITIZE_ALPHANUM);
     if ($ns == AJXP_CACHE_SERVICE_NS_SHARED) {
         ConfService::clearAllCaches();
     } else {
         CacheService::deleteAll($ns);
     }
     HTMLWriter::charsetHeader("text/json");
     echo json_encode(["result" => "ok"]);
 }
 public function url_stat($path, $flags)
 {
     $id = $this->computeCacheId($path, "stat");
     if (CacheService::contains(AJXP_CACHE_SERVICE_NS_NODES, $id)) {
         $stat = CacheService::fetch(AJXP_CACHE_SERVICE_NS_NODES, $id);
         if (is_array($stat)) {
             return $stat;
         }
     }
     $stat = parent::url_stat($path, $flags);
     CacheService::save(AJXP_CACHE_SERVICE_NS_NODES, $id, $stat);
     return $stat;
 }
示例#15
0
 /**
  * Add a new file.
  *
  */
 public function uploadAction()
 {
     if (!$this->_getParam('updated')) {
         $this->_setParam('updated', date('Y-m-d H:i:s'));
     }
     $model = null;
     $parent = '';
     try {
         $params = $this->filterParams($this->_getAllParams());
         $doUpload = false;
         if (isset($_FILES['file']) && strlen(ifset($_FILES['file'], 'tmp_name', ''))) {
             $doUpload = true;
         }
         $filename = ifset($this->_getAllParams(), 'filename');
         if (!strlen($filename) && $doUpload) {
             $filename = $_FILES['file']['name'];
         }
         $parent = trim(base64_decode($this->_getParam('parent')), " /");
         $id = $this->_getParam('id');
         if ($id) {
             // updating
             $file = $this->fileService->getFile($id);
         } else {
             if ($doUpload == false) {
                 // if we're not doing an upload, but the file doesn't
                 // exist yet, lets bail
                 throw new Exception("You must upload a file");
             }
             $file = $this->fileService->createFile($filename, $parent);
         }
         if ($doUpload) {
             $this->fileService->setFile($file, $_FILES['file']['tmp_name']);
         }
         $params = $this->_getAllParams();
         $params['filename'] = $filename;
         if (!empty($parent)) {
             $params['path'] = $parent;
         }
         $file->bind($params);
         $this->fileService->saveFile($file);
         $this->cacheService->expire($parent);
     } catch (InvalidModelException $ime) {
         $this->flash("Invalid model: " . $ime->getMessages());
         $model = new File();
         $model->bind($this->_getAllParams());
         $this->editAction($model);
         return;
     } catch (Exception $e) {
         $this->flash(get_class($e) . ': ' . $e->getMessage());
         error_log(get_class($e) . ': ' . $e->getMessage());
         error_log($e->getTraceAsString());
         $model = new File();
         $model->bind($this->_getAllParams());
         $this->editAction($model);
         return;
     }
     $picker = $this->_getParam('picker');
     $returnUrl = $this->_getParam('returnurl');
     if (!empty($returnUrl)) {
         $this->redirect(base64_decode($this->_getParam('returnurl')), '', array('picker' => $picker));
     } else {
         $this->redirect('file', 'index', array('picker' => $picker, 'parent' => base64_encode($parent)));
     }
 }
示例#16
0
        }
    }
    return true;
}
/**
$checker = init_checker();
if (!$checker)
    die("domain not authorized");
    **/
$sys_config = (require APP_ROOT_PATH . 'system/config.php');
function app_conf($name)
{
    return stripslashes($GLOBALS['sys_config'][$name]);
}
require APP_ROOT_PATH . 'system/cache/Cache.php';
$cache = CacheService::getInstance();
require_once APP_ROOT_PATH . "system/cache/CacheFileService.php";
$fcache = new CacheFileService();
$fcache->set_dir(APP_ROOT_PATH . "public/runtime/data/");
require APP_ROOT_PATH . 'system/db/db.php';
define('DB_PREFIX', app_conf('DB_PREFIX'));
if (!file_exists(APP_ROOT_PATH . 'public/runtime/app/db_caches/')) {
    mkdir(APP_ROOT_PATH . 'public/runtime/app/db_caches/', 0777);
}
$pconnect = false;
$db = new mysql_db(app_conf('DB_HOST') . ":" . app_conf('DB_PORT'), app_conf('DB_USER'), app_conf('DB_PWD'), app_conf('DB_NAME'), 'utf8', $pconnect);
require APP_ROOT_PATH . 'system/template/template.php';
if (!file_exists(APP_ROOT_PATH . 'public/runtime/app/tpl_caches/')) {
    mkdir(APP_ROOT_PATH . 'public/runtime/app/tpl_caches/', 0777);
}
if (!file_exists(APP_ROOT_PATH . 'public/runtime/app/tpl_compiled/')) {
示例#17
0
 /**
  * Save a project
  *
  * @param array|Project $params
  */
 public function saveProject($params)
 {
     $this->dbService->beginTransaction();
     // Double check to see whether the children projects are actually
     // a parent of the selected parent
     $pid = 0;
     $parent = 0;
     $project = null;
     $clientid = 0;
     if (is_array($params)) {
         $pid = ifset($params, 'id');
         $parent = ifset($params, 'parentid');
         if ($pid) {
             $project = $this->getProject($pid);
             $clientid = ifset($params, 'clientid', $project->clientid);
         }
     } else {
         $pid = $params->id;
         $parent = $params->parentid;
         $project = $params;
         $clientid = $project->clientid;
     }
     if ($pid) {
         // check the current parent client, if it's changed we need to update all our
         // child projects as well to let them know that the parent is now different
         $proj = $this->dbService->getById($pid, 'Project');
         $updateChildren = false;
         if ($proj->clientid != $clientid) {
             // update all the children too
             $updateChildren = true;
         }
         // get all the children (including grandchildren and milestones)
         /* @var $project Project */
         $children = $project->getContainedMilestones();
         // see if the selected parent is in the list of children at all
         foreach ($children as $childProject) {
             if ($childProject->id == $parent) {
                 throw new Exception("Cannot create recursive project hierarchy");
             }
             $this->log->debug("Updating project " . $childProject->title . " to client {$clientid}");
             if ($updateChildren) {
                 $childProject->clientid = $clientid;
                 $this->dbService->saveObject($childProject, 'Project');
             }
         }
     } else {
         // we're creating a new project, so lets update the cache list
         $this->cacheService->expire($this->clientProjectsCacheKey($clientid));
     }
     if ($params instanceof Project) {
         $this->updateProjectEstimate($params);
     }
     $savedProject = $this->dbService->saveObject($params, 'Project');
     // If this project's due date is greater than the parent's due date,
     // then update that parent's due date
     if ($savedProject && $savedProject->parentid) {
         $parentProject = $this->dbService->getById($savedProject->parentid, 'Project');
         $parentEnd = strtotime($parentProject->due);
         $thisEnd = strtotime($savedProject->due);
         if ($thisEnd > $parentEnd) {
             $parentProject->due = $savedProject->due;
             $this->saveProject($parentProject);
             $group = $this->groupService->getGroup($parentProject->ownerid);
             // Only send if the group exists
             if ($group) {
                 $users = $this->groupService->getUsersInGroup($group);
                 $msg = new TemplatedMessage('project-end-updated.php', array('model' => $parentProject));
                 try {
                     $this->notificationService->notifyUser("Project due date changed", $users, $msg);
                 } catch (Exception $e) {
                     $this->log->warn("Failed sending project update email");
                 }
             }
         }
         if (mb_strlen($savedProject->actualstart) && !mb_strlen($parentProject->actualstart)) {
             $parentProject->actualstart = $savedProject->actualstart;
             $this->saveProject($parentProject);
         }
     }
     $this->dbService->commit();
     return $savedProject;
 }