/** * Saves the contents of the source files to the cache file or removes it * depending on the number of the source files * * @param array $sourceFiles Source file paths * @param string $cacheFile Cache file paths */ protected function cacheExtensionFiles(array $sourceFiles, $cacheFile) { if (count($sourceFiles) > 0) { $sourceFiles = $this->sortExtensionFiles($sourceFiles); $contents = $this->getExtensionFileContents($sourceFiles); $dirName = dirname($cacheFile); if (!file_exists($dirName)) { mkdir_recursive($dirName, true); } SugarAutoLoader::put($cacheFile, $contents, true); } else { if (file_exists($cacheFile)) { SugarAutoLoader::unlink($cacheFile, 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; }
/** * Saves the dropdown as an Extension, and rebuilds the extensions for given language * * @param string $dropdownName - dropdown name, used for file name * @param string $contents - the edited dropdown contents * @param string $lang - the edited dropdown language * @return bool Success */ protected function saveContents($dropdownName, $contents, $lang) { $fileName = $this->getExtensionFilePath($dropdownName, $lang); if ($fileName) { if (SugarAutoLoader::put($fileName, $contents, true)) { return true; } $GLOBALS['log']->fatal("Unable to write edited dropdown language to file: {$fileName}"); } return false; }
/** * @return bool * @param array contents $app_list_strings * @param string $language * @param string $custom_dir_name * @desc Saves the app_list_strings to file in the 'custom' dir. */ function save_custom_app_list_strings_contents($contents, $language, $cache_index = 'app_list_strings') { $dirname = 'custom/include/language'; if (SugarAutoLoader::ensureDir($dirname)) { $filename = "{$dirname}/{$language}.lang.php"; if (!SugarAutoLoader::put($filename, $contents, true)) { $GLOBALS['log']->fatal("Unable to write edited language pak to file: {$filename}"); } else { $cache_key = $cache_index . '.' . $language; sugar_cache_clear($cache_key); return true; } } else { $GLOBALS['log']->fatal("Unable to create dir: {$dirname}"); } return false; }
/** * Save source's config to custom directory */ public function saveConfig() { $config_str = "<?php\n/***CONNECTOR SOURCE***/\n"; // Handle encryption if (!empty($this->_config['encrypt_properties']) && is_array($this->_config['encrypt_properties']) && !empty($this->_config['properties'])) { require_once 'include/utils/encryption_utils.php'; foreach ($this->_config['encrypt_properties'] as $name) { if (!empty($this->_config['properties'][$name])) { $this->_config['properties'][$name] = blowfishEncode(blowfishGetKey('encrypt_field'), $this->_config['properties'][$name]); } } } foreach ($this->_config as $key => $val) { if (!empty($val)) { $config_str .= $this->getConfigString($key, $val); } } $dir = str_replace('_', '/', get_class($this)); if (!file_exists("custom/modules/Connectors/connectors/sources/{$dir}")) { mkdir_recursive("custom/modules/Connectors/connectors/sources/{$dir}"); } SugarAutoLoader::put("custom/modules/Connectors/connectors/sources/{$dir}/config.php", $config_str, true); }