public function setUp()
 {
     SugarCache::$isCacheReset = false;
     if (empty($GLOBALS['current_language'])) {
         $GLOBALS['current_language'] = $GLOBALS['sugar_config']['default_language'];
     }
 }
Example #2
0
 /**
  * initializes the cache in question
  */
 protected static function _init()
 {
     $lastPriority = 1000;
     $locations = array('include/SugarCache', 'custom/include/SugarCache');
     foreach ($locations as $location) {
         if (sugar_is_dir($location) && ($dir = opendir($location))) {
             while (($file = readdir($dir)) !== false) {
                 if ($file == ".." || $file == "." || !is_file("{$location}/{$file}")) {
                     continue;
                 }
                 require_once "{$location}/{$file}";
                 $cacheClass = basename($file, ".php");
                 if (class_exists($cacheClass) && is_subclass_of($cacheClass, 'SugarCacheAbstract')) {
                     $GLOBALS['log']->debug("Found cache backend {$cacheClass}");
                     $cacheInstance = new $cacheClass();
                     if ($cacheInstance->useBackend() && $cacheInstance->getPriority() < $lastPriority) {
                         $GLOBALS['log']->debug("Using cache backend {$cacheClass}, since " . $cacheInstance->getPriority() . " is less than " . $lastPriority);
                         self::$_cacheInstance = $cacheInstance;
                         $lastPriority = $cacheInstance->getPriority();
                     }
                 }
             }
         }
     }
 }
Example #3
0
 public function tearDown()
 {
     if ($this->module_installer) {
         $this->module_installer->uninstall_extensions();
     }
     if (file_exists($this->module_installer->base_dir . "/test.ext.php")) {
         @unlink($this->module_installer->base_dir . "/test.ext.php");
     }
     SugarCache::$isCacheReset = false;
 }
 public function tearDown()
 {
     // clear out the test cache if we haven't already
     if (sugar_cache_retrieve($this->_cacheKey1)) {
         sugar_cache_clear($this->_cacheKey1);
     }
     if (sugar_cache_retrieve($this->_cacheKey2)) {
         sugar_cache_clear($this->_cacheKey2);
     }
     if (sugar_cache_retrieve($this->_cacheKey3)) {
         sugar_cache_clear($this->_cacheKey3);
     }
     SugarCache::$isCacheReset = false;
 }
 public function tearDown()
 {
     $this->removeCustomAppStrings();
     $this->removeModuleStrings(array('Accounts'));
     SugarTestUserUtilities::removeAllCreatedAnonymousUsers();
     unset($GLOBALS['current_user']);
     unset($GLOBALS['beanList']);
     unset($GLOBALS['beanFiles']);
     SugarCache::$isCacheReset = false;
     if (!empty($this->language_contents)) {
         foreach ($this->language_contents as $key => $contents) {
             sugar_file_put_contents("custom/modules/{$key}/language/en_us.lang.php", $contents);
         }
     }
 }
Example #6
0
 function set($key, $value)
 {
     parent::set($key, $value);
     // caching is turned off
     if (!$GLOBALS['external_cache_enabled']) {
         return;
     }
     $external_key = $this->_realKey($key);
     if (EXTERNAL_CACHE_DEBUG) {
         SugarCache::log("Step 3: Converting key ({$key}) to external key ({$external_key})");
     }
     zput($external_key, $value, $this->timeout);
     if (EXTERNAL_CACHE_DEBUG) {
         SugarCache::log("Step 4: Added key to sMash cache {$external_key} with value ({$value}) to be stored for " . EXTERNAL_CACHE_INTERVAL_SECONDS . " seconds");
     }
 }
Example #7
0
 public function tearDown()
 {
     $mbc = new ModuleBuilderController();
     $this->currencyFieldDef1['name'] = 'c1_c';
     $_REQUEST = $this->currencyFieldDef1;
     $mbc->action_DeleteField();
     $this->currencyFieldDef2['name'] = 'c2_c';
     $_REQUEST = $this->currencyFieldDef2;
     $mbc->action_DeleteField();
     SugarTestUserUtilities::removeAllCreatedAnonymousUsers();
     unset($GLOBALS['current_user']);
     unset($GLOBALS['beanList']);
     unset($GLOBALS['beanFiles']);
     unset($GLOBALS['app_list_strings']);
     $_REQUEST = array();
     SugarCache::$isCacheReset = false;
 }
Example #8
0
 /**
  * initializes the cache in question
  */
 protected static function _init()
 {
     $lastPriority = 1000;
     $locations = SugarAutoLoader::getFilesCustom('include/SugarCache');
     if (empty($locations)) {
         $locations = array('include/SugarCache/SugarCacheMemory.php');
     }
     foreach ($locations as $location) {
         $cacheClass = basename($location, ".php");
         if ($cacheClass == 'SugarCache') {
             continue;
         }
         require_once $location;
         if (class_exists($cacheClass) && is_subclass_of($cacheClass, 'SugarCacheAbstract')) {
             $GLOBALS['log']->debug("Found cache backend {$cacheClass}");
             $cacheInstance = new $cacheClass();
             if ($cacheInstance->useBackend() && $cacheInstance->getPriority() < $lastPriority) {
                 $GLOBALS['log']->debug("Using cache backend {$cacheClass}, since " . $cacheInstance->getPriority() . " is less than " . $lastPriority);
                 self::$_cacheInstance = $cacheInstance;
                 $lastPriority = $cacheInstance->getPriority();
             }
         }
     }
 }
 public function testHandleRemainingRelateFields()
 {
     // create a test relationship
     // save cache reset value
     $_cacheResetValue = SugarCache::$isCacheReset;
     //$rel = $this->createRelationship('Accounts');
     $rel = SugarTestRelationshipUtilities::createRelationship(array('relationship_type' => 'one-to-many', 'lhs_module' => 'Accounts', 'rhs_module' => 'Accounts'));
     if ($rel == false) {
         $this->fail('Relationship Not Created');
     }
     $rel_name = $rel->getName();
     $id = $rel->getIDName('Accounts');
     $acc1 = SugarTestAccountUtilities::createAccount();
     $acc2 = SugarTestAccountUtilities::createAccount();
     $macc = new MockAccountSugarBean();
     $macc->disable_row_level_security = true;
     $macc->retrieve($acc2->id);
     $macc->{$id} = $acc1->id;
     $ret = $macc->handle_remaining_relate_fields();
     $this->assertContains($rel_name, $ret['add']['success']);
     $macc->rel_fields_before_value[$id] = $acc1->id;
     $macc->{$id} = '';
     $ret = $macc->handle_remaining_relate_fields();
     $this->assertContains($rel_name, $ret['remove']['success']);
     // variable cleanup
     // delete the test relationship
     //$this->removeRelationship($rel_name, 'Accounts');
     SugarTestRelationshipUtilities::removeAllCreatedRelationships();
     unset($macc);
     SugarTestAccountUtilities::removeAllCreatedAccounts();
     // reset the isCacheReset Value since this is all one request.
     SugarCache::$isCacheReset = $_cacheResetValue;
 }
 function _processGet($key, $value)
 {
     if (!empty($value)) {
         if (EXTERNAL_CACHE_DEBUG) {
             SugarCache::log("{$this->_name}:: Retrieved from external cache: {$key}", 'pass');
         }
         $GLOBALS['external_cache_request_external_hits']++;
         $this->_cache[$key] = $value;
         return $this->_cache[$key];
     }
     if (EXTERNAL_CACHE_DEBUG) {
         SugarCache::log("{$this->_name}:: External cache retrieve failed: {$key}", 'fail');
     }
     return null;
 }
Example #11
0
 protected function assertPreConditions()
 {
     if (isset($GLOBALS['log'])) {
         $GLOBALS['log']->info("START TEST: {$this->getName(false)}");
     }
     SugarCache::instance()->flush();
 }
Example #12
0
 public function tearDown()
 {
     if (!empty($this->_savedSearchDefs)) {
         file_put_contents("custom/modules/ProjectTask/metadata/searchdefs.php", $this->_savedSearchDefs);
     } else {
         @unlink("custom/modules/ProjectTask/metadata/searchdefs.php");
     }
     if (!empty($this->_savedSearchFields)) {
         file_put_contents("modules/ProjectTask/metadata/SearchFields.php", $this->_savedSearchFields);
     } else {
         @unlink("modules/ProjectTask/metadata/SearchFields.php");
     }
     SugarTestProjectTaskUtilities::removeAllCreatedProjectTasks();
     SugarTestProjectUtilities::removeAllCreatedProjects();
     SugarTestAccountUtilities::removeAllCreatedAccounts();
     $this->relationships->delete($this->relationship->getName());
     $this->relationships->save();
     parent::tearDown();
     SugarCache::$isCacheReset = false;
     SugarTestHelper::tearDown();
     $GLOBALS['reload_vardefs'] = true;
     $bean = new ProjectTask();
     unset($GLOBALS['reload_vardefs']);
 }
Example #13
0
 private function _getStatistics()
 {
     $endTime = microtime(true);
     $deltaTime = $endTime - $GLOBALS['startTime'];
     $response_time_string = $GLOBALS['app_strings']['LBL_SERVER_RESPONSE_TIME'] . ' ' . number_format(round($deltaTime, 2), 2) . ' ' . $GLOBALS['app_strings']['LBL_SERVER_RESPONSE_TIME_SECONDS'];
     $return = $response_time_string;
     // $return .= '<br />';
     if (!empty($GLOBALS['sugar_config']['show_page_resources'])) {
         // Print out the resources used in constructing the page.
         $included_files = get_included_files();
         // take all of the included files and make a list that does not allow for duplicates based on case
         // I believe the full get_include_files result set appears to have one entry for each file in real
         // case, and one entry in all lower case.
         $list_of_files_case_insensitive = array();
         foreach ($included_files as $key => $name) {
             // preserve the first capitalization encountered.
             $list_of_files_case_insensitive[mb_strtolower($name)] = $name;
         }
         $return .= $GLOBALS['app_strings']['LBL_SERVER_RESPONSE_RESOURCES'] . '(' . DBManager::getQueryCount() . ',' . sizeof($list_of_files_case_insensitive) . ')<br>';
         // Display performance of the internal and external caches....
         $cacheStats = SugarCache::instance()->getCacheStats();
         $return .= "External cache (hits/total=ratio) local ({$cacheStats['localHits']}/{$cacheStats['requests']}=" . round($cacheStats['localHits'] * 100 / $cacheStats['requests'], 0) . "%)";
         $return .= " external ({$cacheStats['externalHits']}/{$cacheStats['requests']}=" . round($cacheStats['externalHits'] * 100 / $cacheStats['requests'], 0) . "%)<br />";
         $return .= " misses ({$cacheStats['misses']}/{$cacheStats['requests']}=" . round($cacheStats['misses'] * 100 / $cacheStats['requests'], 0) . "%)<br />";
     }
     $return .= $this->logMemoryStatistics();
     return $return;
 }
Example #14
0
 /**
  * Performs basic logging for messages generated by the external caching mechanism
  *
  * Currently this only outputs directly to the screen as it's only used internally.
  *
  * There are five supported $type values:
  *  neutral     :: just a log message with information value
  *  pass        :: a pass that attention should be brought to
  *  lightpass   :: a pass without much consequence
  *  fail        :: a fail that attention should be brought to
  *  lightfail   :: a failure without much consequence, or one that might succeed later in
  *                 the execution chain
  *
  * @param string $msg Message to output.  Note it will be filtered through htmlspecialchars()
  * @param string $type Type of message to output
  */
 function log($msg, $type = 'neutral')
 {
     static $messages = array();
     static $valid_types = array('neutral' => '', 'pass' => '', 'lightpass' => '', 'fail' => '', 'lightfail' => '');
     if (!isset($valid_types[$type])) {
         SugarCache::log("Invalid type provided: {$type}", 'fail');
         $type = 'neutral';
     }
     $session_id = session_id();
     if (empty($session_id)) {
         // add to stack of messages to output after the session starts so we don't kill the headers
         $messages[] = array('message' => htmlspecialchars($msg), 'type' => $type);
     } else {
         if ($messages !== false) {
             // output base styles on first round trip - this doesn't worry that its
             // not in the proper place as its for debugging purposes only.
             echo "<style type='text/css'>" . "hr +span { padding:3px 5px; display:block; } " . "hr +.pass { background-color:green; color: white; } " . "hr +.lightpass { background-color: #CFC; color:black; }" . "hr +.fail { background-color:red; color:white; } " . "hr +.lightfail { background-color:#F99; color: black; }" . "hr +.neutral { background-color:#FFFFE0; color:black; } " . "</style>";
         }
         if ($messages !== false && count($messages) > 0) {
             // clear stack of messages;
             echo '<hr />Messages logged prior to session starting...<hr />', "\n";
             foreach ($messages as $id => $old_msg) {
                 echo "<hr /><span class='{$old_msg['type']}'>{$id} -- {$old_msg['message']}</span><hr />\n";
             }
             echo "<hr />End of messages prior to session starting...<hr />\n";
         }
         $messages = false;
         $msg = htmlspecialchars($msg);
         echo "<hr /><span class='{$type}'>{$msg}</span><hr />\n";
     }
 }
Example #15
0
 /**
  * Clean up all registered variables and restore $initVars and $systemVars
  * @static
  * @return bool status of tearDown
  */
 public static function tearDown()
 {
     self::init();
     foreach (self::$registeredVars as $varName => $isCalled) {
         if ($isCalled) {
             unset(self::$registeredVars[$varName]);
             if (method_exists(__CLASS__, 'tearDown_' . $varName)) {
                 call_user_func(__CLASS__ . '::tearDown_' . $varName, array());
             } elseif (isset($GLOBALS[$varName])) {
                 unset($GLOBALS[$varName]);
             }
         }
     }
     // Restoring of system variables
     foreach (self::$initVars as $scope => $vars) {
         foreach ($vars as $name => $value) {
             $GLOBALS[$scope][$name] = $value;
         }
     }
     // Restoring of theme
     SugarThemeRegistry::set(self::$systemVars['SugarThemeRegistry']->dirName);
     SugarCache::$isCacheReset = false;
     return true;
 }
 /**
  * Reset the cache for this request
  */
 public function reset()
 {
     $this->_localStore = array();
     SugarCache::$isCacheReset = true;
 }
Example #17
0
 /**
  * Retrieve the value of a given key
  *
  * @param string $key
  * @return mixed
  */
 function get($key)
 {
     $GLOBALS['external_cache_request_local_total']++;
     if (isset($this->_cache[$key])) {
         if (EXTERNAL_CACHE_DEBUG) {
             SugarCache::log("BASE: found {$key}", 'lightpass');
         }
         $GLOBALS['external_cache_request_local_hits']++;
         return $this->_cache[$key];
     } else {
         if (EXTERNAL_CACHE_DEBUG) {
             $type = $this->_my_class_name == 'sugarcache_base' ? 'fail' : 'lightfail';
             SugarCache::log("BASE: unable to locate {$key}", $type);
         }
     }
 }
Example #18
0
 /**
  * Deletes an existing template
  *
  * @param module string module name
  * @param view string view need (eg DetailView, EditView, etc)
  */
 function deleteTemplate($module, $view)
 {
     if (is_file($this->cacheDir . $this->templateDir . $module . '/' . $view . '.tpl')) {
         // Bug #54634 : RTC 18144 : Cannot add more than 1 user to role but popup is multi-selectable
         if (!isset($this->ss)) {
             $this->loadSmarty();
         }
         $cache_file_name = $this->ss->_get_compile_path($this->cacheDir . $this->templateDir . $module . '/' . $view . '.tpl');
         SugarCache::cleanFile($cache_file_name);
         return unlink($this->cacheDir . $this->templateDir . $module . '/' . $view . '.tpl');
     }
     return false;
 }
Example #19
0
    static function addLabels ($language , $labels , $moduleName , $basepath = null, $forRelationshipLabel = false)
    {

        $GLOBALS [ 'log' ]->debug ( "ParserLabel->addLabels($language, \$labels, $moduleName, $basepath );" ) ;
        $GLOBALS [ 'log' ]->debug ( "\$labels:" . print_r ( $labels, true ) ) ;

        $deployedModule = false ;
        if (is_null ( $basepath ))
        {
            $deployedModule = true ;
            $basepath = "custom/modules/$moduleName/language" ;
            if($forRelationshipLabel){
            	$basepath = "custom/modules/$moduleName/Ext/Language" ;
            }
            if (! is_dir ( $basepath ))
            {
                mkdir_recursive($basepath);
            }
        }

        $filename = "$basepath/$language.lang.php" ;
        if($forRelationshipLabel){
        	$filename = "$basepath/$language.lang.ext.php" ;
     	}
        $dir_exists = is_dir ( $basepath ) ;

        $mod_strings = array ( ) ;

        if ($dir_exists)
        {
            if (file_exists ( $filename ))
            {
                // obtain $mod_strings
                include ($filename) ;
            }else if($forRelationshipLabel){
            	$fh = fopen ($filename, 'a');
            	fclose($fh);
            }
        } else
        {
            return false ;
        }

        	$changed = false ;

        //$charset = (isset($app_strings['LBL_CHARSET'])) ? $app_strings['LBL_CHARSET'] : $GLOBALS['sugar_config']['default_charset'] ;

	        foreach ( $labels as $key => $value )
	        {
            if (! isset ( $mod_strings [ $key ] ) || strcmp ( $value, $mod_strings [ $key ] ) != 0)
	            {
                    $mod_strings [$key] = to_html(strip_tags(from_html($value))); // must match encoding used in view.labels.php
	                $changed = true ;
	            }
	        }

	        if ($changed)
	        {
            $GLOBALS [ 'log' ]->debug ( "ParserLabel->addLabels: writing new mod_strings to $filename" ) ;
	            $GLOBALS [ 'log' ]->debug ( "ParserLabel->addLabels: mod_strings=".print_r($mod_strings,true) ) ;
            if (! write_array_to_file ( "mod_strings", $mod_strings, $filename ))
	            {
                $GLOBALS [ 'log' ]->fatal ( "Could not write $filename" ) ;
	            } else
	            {
	                // if we have a cache to worry about, then clear it now
                if ($deployedModule)
	                {
                            SugarCache::cleanOpcodes();
	                    $GLOBALS [ 'log' ]->debug ( "PaserLabel->addLabels: clearing language cache" ) ;
	                    $cache_key = "module_language." . $language . $moduleName ;
	                    sugar_cache_clear ( $cache_key ) ;
	                    LanguageManager::clearLanguageCache ( $moduleName, $language ) ;
	                }
	            }
	        }

        // Fix for bug #51
        // when the label is recreated it defaults back to the original value (In this case its "User").

        // Solution:
        // 1. Changes to the label names should go to custom/Extension/modules/{ModuleName}/Ext/Language
        // This is done in case different users edit the same Relationship concurrently.
        // The changes from custom/Extension/modules/{ModuleName}/Ext/Language
        // will overwrite stuff in custom/modules/{ModuleName}/Ext/Language/en_us.lang.ext.php after
        //  Quick Repair and Rebuild is applied.
        if($forRelationshipLabel) {
            if(!empty($_POST[view_module]) && !empty($_POST[relationship_name]) && !empty($_POST[rhs_label]) && !empty($_POST[lhs_module])) {
                // 1. Overwrite custom/Extension/modules/{ModuleName}/Ext/Language
                $extension_basepath = "custom/Extension/modules/" . $_POST[view_module] . "/Ext/Language";
                mkdir_recursive($extension_basepath);

                $headerString = "<?php\n//THIS FILE IS AUTO GENERATED, DO NOT MODIFY\n";
                $out = $headerString;

                $extension_filename = "$extension_basepath/$language.custom" . $_POST[relationship_name] . ".php";

                $mod_strings = array();
                if (file_exists($extension_filename)) {
                    // obtain $mod_strings
                    include($extension_filename);
                }

                $changed_mod_strings = false;
                foreach ($labels as $key => $value) {
                    foreach ($mod_strings as $key_mod_string => $value_mod_string) {
                        if (strpos($key_mod_string, strtoupper($_POST[relationship_name])) !== false) {
                            $mod_strings[$key_mod_string] = to_html(strip_tags(from_html($_POST[rhs_label]))); // must match encoding used in view.labels.php
                            $changed_mod_strings = true;
                        }
                    }
                }

                foreach ($mod_strings as $key => $val)
                    $out .= override_value_to_string_recursive2('mod_strings', $key, $val);

                $failed_to_write = false;
                try {
                    $file_contents = fopen($extension_filename, 'w');
                    fputs($file_contents, $out, strlen($out));
                    fclose($file_contents);
                } catch (Exception $e) {
                    $GLOBALS ['log']->fatal("Could not write $filename");
                    $GLOBALS ['log']->fatal("Exception " . $e->getMessage());
                    $failed_to_write = true;
                }

                //2. Overwrite custom/Extension/modules/relationships/language/{ModuleName}.php
                // Also need to overwrite custom/Extension/modules/relationships/language/{ModuleName}.php
                // because whenever new relationship is created this place is checked by the system to get
                // all the label names
                $relationships_basepath = "custom/Extension/modules/relationships/language";
                mkdir_recursive($relationships_basepath);

                $headerString = "<?php\n//THIS FILE IS AUTO GENERATED, DO NOT MODIFY\n";
                $out = $headerString;

                $relationships_filename = "$relationships_basepath/" . $_POST[lhs_module] . ".php";


                $mod_strings = array();
                if (file_exists($relationships_filename)) {
                    // obtain $mod_strings
                    include($relationships_filename);
                }

                $changed_mod_strings = false;
                foreach ($labels as $key => $value) {
                    foreach ($mod_strings as $key_mod_string => $value_mod_string) {
                        if (strpos($key_mod_string, strtoupper($_POST[relationship_name])) !== false) {
                            $mod_strings[$key_mod_string] = to_html(strip_tags(from_html($_POST[rhs_label]))); // must match encoding used in view.labels.php
                            $changed_mod_strings = true;
                        }
                    }
                }

                foreach ($mod_strings as $key => $val)
                    $out .= override_value_to_string_recursive2('mod_strings', $key, $val);

                $failed_to_write = false;
                try {
                    $file_contents = fopen($relationships_filename, 'w');
                    fputs($file_contents, $out, strlen($out));
                    fclose($file_contents);
                } catch (Exception $e) {
                    $GLOBALS ['log']->fatal("Could not write $filename");
                    $GLOBALS ['log']->fatal("Exception " . $e->getMessage());
                    $failed_to_write = true;
                }

                if ($changed_mod_strings) {
                    if (!$failed_to_write) {
                        // if we have a cache to worry about, then clear it now
                        if ($deployedModule) {
                            SugarCache::cleanOpcodes();
                            $GLOBALS ['log']->debug("PaserLabel->addLabels: clearing language cache");
                            $cache_key = "module_language." . $language . $moduleName;
                            sugar_cache_clear($cache_key);
                            LanguageManager::clearLanguageCache($moduleName, $language);
                        }
                    }
                }
            }
        }

        return true ;
    }
 public function testStoreAndRetrieveWithTTLNull()
 {
     $sc = SugarCache::instance();
     $cacheStub = $this->getMock(get_class($sc), array('_setExternal'));
     $cacheStub->expects($this->once())->method('_setExternal');
     $cacheStub->set($this->_cacheKey1, $this->_cacheValue1, null);
 }
Example #21
0
 /**
  * Add a set of labels to the language pack for a module, deployed or undeployed
  * 
  * @param string $language Language key, for example 'en_us'
  * @param array $labels The labels to add in the form of an array of System label => Display label pairs
  * @param string $moduleName Name of the module to which to add these labels
  * @param string $basepath Basepath to the file to be written to
  */
 public static function addLabels($language, $labels, $moduleName, $basepath = null)
 {
     $GLOBALS['log']->debug("ParserLabel->addLabels({$language}, \$labels, {$moduleName}, {$basepath});");
     $GLOBALS['log']->debug("\$labels:" . print_r($labels, true));
     $deployedModule = false;
     if (is_null($basepath)) {
         $deployedModule = true;
         $basepath = "custom/Extension/modules/{$moduleName}/Ext/Language";
         if (!SugarAutoLoader::fileExists($basepath)) {
             mkdir_recursive($basepath);
         }
     }
     $filename = "{$basepath}/{$language}.lang.php";
     $mod_strings = array();
     $changed = false;
     if (SugarAutoLoader::fileExists($basepath)) {
         if (SugarAutoLoader::fileExists($filename)) {
             // Get the current $mod_strings
             include $filename;
         }
         foreach ($labels as $key => $value) {
             if (!isset($mod_strings[$key]) || strcmp($value, $mod_strings[$key]) != 0) {
                 // Must match encoding used in view.labels.php
                 $mod_strings[$key] = to_html(strip_tags(from_html($value)));
                 $changed = true;
             }
         }
     } else {
         $changed = true;
     }
     if (!empty($mod_strings) && $changed) {
         $GLOBALS['log']->debug("ParserLabel->addLabels: writing new mod_strings to {$filename}");
         $GLOBALS['log']->debug("ParserLabel->addLabels: mod_strings=" . print_r($mod_strings, true));
         $write = "<?php\n// WARNING: The contents of this file are auto-generated.\n";
         // We can't use normal array writing here since multiple files can be
         // structured differently. This is dirty, yes, but necessary.
         foreach ($mod_strings as $k => $v) {
             $write .= "\$mod_strings['{$k}'] = " . var_export($v, 1) . ";\n";
         }
         if (!SugarAutoLoader::put($filename, $write, true)) {
             $GLOBALS['log']->fatal("Could not write {$filename}");
         } else {
             // if we have a cache to worry about, then clear it now
             if ($deployedModule) {
                 SugarCache::cleanOpcodes();
                 $GLOBALS['log']->debug("PaserLabel->addLabels: clearing language cache");
                 self::rebuildLanguageExtensions($language, $moduleName);
                 $cache_key = "module_language." . $language . $moduleName;
                 sugar_cache_clear($cache_key);
                 LanguageManager::clearLanguageCache($moduleName, $language);
                 MetaDataManager::refreshLanguagesCache($language);
             }
         }
     }
     return true;
 }
Example #22
0
/**
 * Internal -- Determine if there is an external cache available for use.  
 * Currently only Zend Platform is supported.
 */
function check_cache()
{
    if (EXTERNAL_CACHE_DEBUG) {
        SugarCache::log("Checking cache");
    }
    if ($GLOBALS['external_cache_checked'] == false) {
        $GLOBALS['external_cache_checked'] = true;
        $GLOBALS['external_cache_object'] = SugarCache::discover();
    }
    if (EXTERNAL_CACHE_DEBUG) {
        SugarCache::log("Checking cache: " . var_export($GLOBALS['external_cache_enabled'], true));
    }
}
 private function writeUnifiedSearchModulesDisplayFile($unified_search_modules_display)
 {
     if (is_null($unified_search_modules_display) || empty($unified_search_modules_display)) {
         return false;
     }
     sugar_mkdir('custom/modules', null, true);
     if (!write_array_to_file("unified_search_modules_display", $unified_search_modules_display, 'custom/modules/unified_search_modules_display.php')) {
         //Log error message and throw Exception
         global $app_strings;
         $msg = string_format($app_strings['ERR_FILE_WRITE'], array('custom/modules/unified_search_modules_display.php'));
         $GLOBALS['log']->error($msg);
         throw new Exception($msg);
     }
     SugarCache::cleanFile('custom/modules/unified_search_modules_display.php');
     return true;
 }
 static function addLabels($language, $labels, $moduleName, $basepath = null, $forRelationshipLabel = false)
 {
     $GLOBALS['log']->debug("ParserLabel->addLabels({$language}, \$labels, {$moduleName}, {$basepath} );");
     $GLOBALS['log']->debug("\$labels:" . print_r($labels, true));
     $deployedModule = false;
     if (is_null($basepath)) {
         $deployedModule = true;
         $basepath = "custom/modules/{$moduleName}/language";
         if ($forRelationshipLabel) {
             $basepath = "custom/modules/{$moduleName}/Ext/Language";
         }
         if (!is_dir($basepath)) {
             mkdir_recursive($basepath);
         }
     }
     $filename = "{$basepath}/{$language}.lang.php";
     if ($forRelationshipLabel) {
         $filename = "{$basepath}/{$language}.lang.ext.php";
     }
     $dir_exists = is_dir($basepath);
     $mod_strings = array();
     if ($dir_exists) {
         if (file_exists($filename)) {
             // obtain $mod_strings
             include $filename;
         } else {
             if ($forRelationshipLabel) {
                 $fh = fopen($filename, 'a');
                 fclose($fh);
             }
         }
     } else {
         return false;
     }
     $changed = false;
     //$charset = (isset($app_strings['LBL_CHARSET'])) ? $app_strings['LBL_CHARSET'] : $GLOBALS['sugar_config']['default_charset'] ;
     foreach ($labels as $key => $value) {
         if (!isset($mod_strings[$key]) || strcmp($value, $mod_strings[$key]) != 0) {
             $mod_strings[$key] = to_html(strip_tags(from_html($value)));
             // must match encoding used in view.labels.php
             $changed = true;
         }
     }
     if ($changed) {
         $GLOBALS['log']->debug("ParserLabel->addLabels: writing new mod_strings to {$filename}");
         $GLOBALS['log']->debug("ParserLabel->addLabels: mod_strings=" . print_r($mod_strings, true));
         if (!write_array_to_file("mod_strings", $mod_strings, $filename)) {
             $GLOBALS['log']->fatal("Could not write {$filename}");
         } else {
             // if we have a cache to worry about, then clear it now
             if ($deployedModule) {
                 SugarCache::cleanOpcodes();
                 $GLOBALS['log']->debug("PaserLabel->addLabels: clearing language cache");
                 $cache_key = "module_language." . $language . $moduleName;
                 sugar_cache_clear($cache_key);
                 LanguageManager::clearLanguageCache($moduleName, $language);
             }
         }
     }
     return true;
 }
 /**
  * Cache killer, to be defined in child classes as needed.
  */
 protected function _clearCaches()
 {
     if ($this->implementation->isDeployed()) {
         SugarCache::cleanOpcodes();
     }
 }