Exemple #1
0
 function load($classname)
 {
     $classname = preg_replace('[^a-zA-Z0-9_-]', '', $classname);
     if (isset($this->paths[$classname])) {
         require $this->paths[$classname];
         return;
     }
     if (isset($this->paths[strtolower($classname)])) {
         require $this->paths[strtolower($classname)];
         return;
     }
     $cache_id = array('module_component_path', strtolower($classname));
     $cache = Cache::Instance();
     $module_path = $cache->get($cache_id);
     // go and fetch the data and populate the cache
     if ($module_path === FALSE) {
         $module = new ModuleComponent();
         $module->loadBy('name', strtolower($classname));
         if ($module->isLoaded()) {
             if (substr($module->location, -4) === '.php') {
                 $cache->add($cache_id, $module->location);
                 require $module->location;
             }
             return;
         }
     } else {
         require $module_path;
     }
 }
 public static function get($var)
 {
     $return = FALSE;
     if (MEMCACHED_ENABLED) {
         $cache = Cache::Instance();
         $return = $cache->get(array('system_company_settings', $var));
     }
     if (FALSE === $return) {
         //if it's a constant, use that
         $c_var = 'self::' . $var;
         if (defined($c_var)) {
             $return = constant($c_var);
         } else {
             //check for a db-field corresponding to the value. and use that
             $sc = new Systemcompany();
             if (EGS_COMPANY_ID !== 'null' && $sc->isField($var)) {
                 $res = $sc->load(EGS_COMPANY_ID);
                 $return = $sc->{$var};
             } else {
                 //_ indicates a default for a DB-value
                 $c_var = 'self::_' . $var;
                 if (defined($c_var)) {
                     $return = constant($c_var);
                 }
             }
         }
         if (MEMCACHED_ENABLED) {
             $cache->add(array('system_company_settings', $var), $return, 28800);
         }
     }
     return $return;
 }
Exemple #3
0
 public static function initalize($engine)
 {
     if (!in_array($engine, self::$Engines)) {
         $engine = 'Cache_Null';
     }
     if (is_null(Cache::$Instance)) {
         Cache::$Instance = new $engine();
     }
 }
Exemple #4
0
 public function save()
 {
     $this->constraints->removeByField('usercompanyid');
     $array = array();
     $array['fields'] = serialize($this->fields);
     $array['constraints'] = serialize($this->constraints);
     $array['orderby'] = $this->orderby;
     $array['orderdir'] = $this->orderdir;
     $array['perpage'] = $this->perpage;
     $array['page'] = $this->page;
     $array['maxlimit'] = $this->maxlimit;
     $array['lastpage'] = $this->lastpage;
     $array['lastupdated'] = time();
     // instanciate and set the cache
     $cache = Cache::Instance();
     $cache_id = array('searches', EGS_USERNAME, $this->tablename . '_' . $this->search_id);
     $cache->add($cache_id, $array, 1800);
     debug('SearchHandler::save ' . $this->tablename . ' ' . print_r($array, TRUE));
 }
Exemple #5
0
 public static function Delete($n = null, $id = null, $k = 'id')
 {
     settype($id, 'array');
     $cache = Cache::Instance();
     $idstring = join('\',\'', $id);
     $sql = "DELETE FROM `{$n}` WHERE `{$k}` IN('{$idstring}')";
     DB::Query($sql);
     if ($k != 'id') {
         return true;
     }
     Cache::Instance('default')->ClearObject($n, $id);
     return True;
 }
 private function change_table($_data, $_action)
 {
     $sqlarray = $this->DropViewSQL($_data['dataset_name']);
     $dict = $this->setDictionarySchema();
     //		$flds is a string defining the field as follows:-
     //			field_name
     //			field_type - convert the input value into the ADODB type
     //			field_length - optional, enclose in brackets if present
     //			mandatory_field - optional set to NOTNULL if mandatory
     //			field_default_value - optional, preceded by DEFAULT if present
     $flds = $_data['name'];
     if ($_action != 'delete') {
         $flds .= ' ' . DATASET::get_ADODB_field_type($_data['type']);
         $flds .= empty($_data['field_length']) ? '' : ' (' . $_data['length'] . ')';
         $flds .= empty($_data['mandatory']) ? '' : ' NOTNULL';
         $flds .= empty($_data['default_value']) ? '' : ' DEFAULT ' . $_data['default_value'];
     }
     //		ChangeTableSQL generates incorrect sql syntax for postgres
     //		$sqlarray = $dict->ChangeTableSQL($data['dataset_name'], $flds);
     if ($_action == 'alter') {
         if ($_data['old_name'] != $_data['name']) {
             $sqlarray = array_merge($sqlarray, $dict->RenameColumnSQL($_data['dataset_name'], $_data['old_name'], $_data['name']));
         }
         $sqlarray = array_merge($sqlarray, $dict->AlterColumnSQL($_data['dataset_name'], $flds));
     } elseif ($_action == 'delete') {
         $sqlarray = array_merge($sqlarray, $dict->DropColumnSQL($_data['dataset_name'], $flds));
     } elseif ($_action == 'add') {
         $sqlarray = array_merge($sqlarray, $dict->AddColumnSQL($_data['dataset_name'], $flds));
     }
     $result = $dict->ExecuteSQLArray($sqlarray) == 2;
     if ($result == 2) {
         // Refresh the cache
         $tablename = $this->getTablename($_data['dataset_name']);
         $cache_id = array('table_fields', $tablename);
         $cache = Cache::Instance();
         $cache->delete($cache_id);
         Fields::getFields_static($tablename, TRUE);
     }
     return $result == 2;
 }
 public static function initalize($engine = 'Cache_Static')
 {
     try {
         // Handle engine failover here
         switch ($engine) {
             case 'Cache_StaticMemcache':
                 if (Cache_StaticMemcache::isEnabled()) {
                     break;
                 }
             case 'Cache_Memcache':
                 if (Cache_Memcache::isEnabled()) {
                     break;
                 }
             case 'Cache_Static':
             default:
                 $engine = 'Cache_Static';
         }
         if (is_null(Cache::$Instance)) {
             Cache::$Instance = new $engine();
         }
     } catch (Exception $e) {
         //if (Conf::read('DEBUG')) {
         //	throw $e;
         //} else {
         return null;
         //}
     }
 }
Exemple #8
0
 *
 *	Released under GPLv3 license; see LICENSE.
 **/
/* $Revision: 1.11 $ */
// clear the memcached cache
// we don't need to include Cache.php, System::checkSystem() does that for us
//require_once 'conf/config.php';
require_once 'system.php';
$arguments = getopt("f:h:");
//echo 'Arguments='.print_r($arguments, true)."\n";
if (empty($arguments['f'])) {
    echo "No file path\n";
    exit;
}
if (empty($arguments['h'])) {
    echo "No host name supplied\n";
    exit;
}
$_SERVER['DOCUMENT_ROOT'] = $arguments['f'];
$_SERVER['HTTP_HOST'] = $arguments['h'];
echo 'Clearing Caches in ' . $_SERVER['DOCUMENT_ROOT'];
// instantiate system and checks
$system = System::Instance();
$system->check_system();
// Disable any caching to ensure any new lib files are loaded
$system->load_essential(TRUE);
// flush the cache
$cache = Cache::Instance();
$cache->flush();
echo " - Done\n";
// end of clear_memcached.php
Exemple #9
0
 public function flush()
 {
     $flash = Flash::Instance();
     $cache = Cache::Instance();
     $cache->flush();
     if (MEMCACHED_ENABLED) {
         $flash->addMessage("Cache successfully flushed");
     } else {
         $flash->addWarning('Memcached is disabled');
         $flash->addMessage('Attempted to clear file cache');
     }
     sendBack();
 }
Exemple #10
0
 public static function GetQueryResult($sql, $one = true, $cache = 0)
 {
     $mkey = md5($sql . $one);
     if ($cache > 0) {
         $ret = Cache::Instance('default')->Get($mkey);
         if ($ret) {
             return $ret;
         }
     }
     $ret = array();
     if ($result = self::Query($sql)) {
         while ($row = mysql_fetch_assoc($result)) {
             $row = array_change_key_case($row, CASE_LOWER);
             if ($one) {
                 $ret = $row;
                 break;
             } else {
                 array_push($ret, $row);
             }
         }
         @mysql_free_result($result);
     }
     if ($cache > 0 && $ret) {
         Cache::Instance('default')->Set($mkey, $ret, 0, $cache);
     }
     return $ret;
 }
Exemple #11
0
 public static function makeCompany()
 {
     if (defined('PRODUCTION') && PRODUCTION) {
         $company = FALSE;
         if (MEMCACHED_ENABLED) {
             $cache = Cache::Instance();
             $company = $cache->get(array('company_blank', $tablename));
         }
         if (FALSE === $company) {
             $company = DataObjectFactory::Factory('Company');
             if (MEMCACHED_ENABLED) {
                 $cache->add(array('company_blank', $tablename), serialize($company), 28800);
             }
         } else {
             $company = unserialize($company);
         }
         return $company;
     }
     $company = DataObjectFactory::Factory('Company');
     return $company;
 }
Exemple #12
0
 public function get_lib_files($_disable_cache = FALSE)
 {
     $cache_id = array('resources', 'lib_root');
     $cache = Cache::Instance();
     if ($_disable_cache) {
         $files = FALSE;
     } else {
         $files = $cache->get($cache_id);
     }
     if ($files === FALSE) {
         $files = self::scanDirectories(LIB_ROOT, '', FALSE);
         // attempt to set the cache value
         $cache->add($cache_id, $files);
     }
     return $files;
 }
Exemple #13
0
 /**
  * Set a custom orderby and orderdir from a YAML file
  *
  * Setting an order in the YAML file will override
  * the order set on the Model
  *
  * Example YAML:
  *
  *      ---
  *      SOrder:
  *          orderby:
  *              - 'customer'
  *              - 'order_number'
  *          orderdir:
  *              - 'DESC'
  *              - 'DESC'
  *
  * @param string $yaml_file
  * @throws ParseException
  */
 public function setCustomModelOrder($yaml_file = NULL)
 {
     if (is_null($yaml_file)) {
         return;
     }
     // Load model sort overrides from YAML file
     $cache = Cache::Instance();
     $cache_id = 'custom_model_order';
     $model = get_class($this);
     $custom_order = $cache->get($cache_id);
     $flash = Flash::Instance();
     try {
         // if the cache key is empty, load it from the file
         if ($custom_order === FALSE && file_exists($yaml_file)) {
             $custom_order = Yaml::parse(file_get_contents($yaml_file));
             foreach ($custom_order as $mod_order) {
                 if (count(array_diff($mod_order['orderdir'], ['ASC', 'DESC'])) > 0) {
                     throw new ParseException('invalid order direction specified');
                 }
             }
             $cache->add($cache_id, $custom_order);
         }
         // if the current model matches a custom sort...
         if (isset($custom_order[$model])) {
             $this->getDisplayFields();
             if (count(array_diff($custom_order[$model]['orderby'], array_keys($this->_fields))) == 0) {
                 $this->orderby = $custom_order[$model]['orderby'];
                 $this->orderdir = $custom_order[$model]['orderdir'];
                 $this->orderoverride = TRUE;
             } else {
                 $fields = implode(', ', array_diff($custom_order[$model]['orderby'], array_keys($this->_fields)));
                 throw new ParseException("field(s) '{$fields}' not found in {$model} model display fields");
             }
         }
     } catch (ParseException $e) {
         $flash->addError('Unable to use custom model sort from ' . $yaml_file . ': ' . $e->getMessage());
     }
 }