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; }
/** * Clean out whatever opcode cache we may have out there. */ function sugar_clean_opcodes() { SugarCache::cleanOpcodes(); }
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 ; }
/** * 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; }
/** * Cache killer, to be defined in child classes as needed. */ protected function _clearCaches() { if ($this->implementation->isDeployed()) { SugarCache::cleanOpcodes(); } }