/**
  * Workflow: Check module builder modules for "moduleList" and "moduleListSingular"
  * labels and translations. Create or append fixed content to package
  * language file to make it compatible with Studio or ModuleBuilder for future changes
  */
 public function run()
 {
     if (empty($this->upgrader->state['MBModules'])) {
         // No MB modules - nothing to do
         return;
     }
     $app_list_strings = return_app_list_strings_language("en_us");
     $changes = array();
     $packages = $this->getPackages();
     foreach ($this->upgrader->state['MBModules'] as $MBModule) {
         // All custom modules will have package key in module name
         $keys = explode('_', $MBModule);
         $packageKey = $keys[0];
         if (!isset($packages[$packageKey])) {
             $this->upgrader->log('FixSingularList: can\'t find package for module: key - ' . $packageKey . '. Script will use current key as package name');
             $packages[$packageKey] = $packageKey;
         }
         $changes[$packageKey] = isset($changes[$packageKey]) ? $changes[$packageKey] : array();
         // Try to add custom module to moduleList
         if (!isset($app_list_strings['moduleList'][$MBModule])) {
             $langFile = $this->getLanguageFilePath($MBModule);
             if (file_exists($langFile)) {
                 $mod_strings = array();
                 require $langFile;
                 $moduleName = isset($mod_strings['LBL_MODULE_NAME']) ? $mod_strings['LBL_MODULE_NAME'] : false;
                 if ($moduleName) {
                     $app_list_strings['moduleList'][$MBModule] = $moduleName;
                     $changes[$packageKey]['moduleList'][$MBModule] = $moduleName;
                 } else {
                     $this->upgrader->log('FixSingularList: warning - module ' . $MBModule . ' do not have module name translation');
                 }
             }
         }
         if (!isset($app_list_strings['moduleListSingular'][$MBModule]) && !empty($app_list_strings['moduleList'][$MBModule])) {
             $changes[$packageKey]['moduleListSingular'][$MBModule] = $app_list_strings['moduleList'][$MBModule];
         }
     }
     $rebuildLang = false;
     foreach ($changes as $packageKey => $content) {
         // if no changes - continue
         if (empty($content)) {
             continue;
         }
         $packageName = $packages[$packageKey];
         $fileName = $this->getPackageLangFile($packageName);
         $values = $this->mergeCustomTranslations($fileName, $content);
         $header = file_get_contents('modules/ModuleBuilder/MB/header.php');
         $file = $header;
         foreach ($values as $key => $array) {
             $file .= override_value_to_string_recursive2('app_list_strings', $key, $array);
         }
         $this->upgrader->putFile($fileName, $file);
         $rebuildLang = true;
     }
     if ($rebuildLang) {
         $mi = new ModuleInstaller();
         $mi->silent = true;
         $mi->rebuild_languages(array('en_us' => 'en_us'));
     }
 }
 public function testoverride_value_to_string_recursive2()
 {
     //execute the method and test if it returns expected values
     //null array
     $expected = null;
     $actual = override_value_to_string_recursive2('tempArray', 'key1', '', false);
     $this->assertSame($actual, $expected);
     //simple array
     $tempArray = array('Key1' => 'value1', 'Key2' => 'value2');
     $expected = "\$['tempArray']['Key1'] = 'value1';\n\$['tempArray']['Key2'] = 'value2';\n";
     $actual = override_value_to_string_recursive2('', 'tempArray', $tempArray);
     $this->assertSame($actual, $expected);
     //complex array
     $tempArray = array();
     $tempArray['Key1']['Key2'] = array('Key3' => 'value', 'Key4' => 'value');
     $expected = "\$tempArray['key1']['Key2']['Key3'] = 'value';\n\$tempArray['key1']['Key2']['Key4'] = 'value';\n";
     $actual = override_value_to_string_recursive2('tempArray', 'key1', $tempArray['Key1']);
     $this->assertSame($actual, $expected);
 }
 /**
  * Append a array of new settings to the file "config_override.php".
  * @param $settings Array of settings
  * @return bool
  * @throws Exception
  */
 public function appendOverrideConfig($settings)
 {
     $file = 'config_override.php';
     $sugar_config = array();
     if (file_exists($file)) {
         $this->upgrader->backupFile($file);
         include $file;
     }
     foreach ($settings as $key => $val) {
         $sugar_config[$key] = $val;
     }
     $out = "<?php\n // created: " . date('Y-m-d H:i:s') . "\n";
     foreach (array_keys($sugar_config) as $key) {
         $out .= override_value_to_string_recursive2('sugar_config', $key, $sugar_config[$key]);
     }
     if (!sugar_file_put_contents_atomic($file, $out)) {
         throw new Exception("Failed writing to the {$file} file.");
     }
     return true;
 }
 function handleOverride()
 {
     global $sugar_config, $sugar_version;
     $sc = SugarConfig::getInstance();
     $overrideArray = $this->readOverride();
     $this->previous_sugar_override_config_array = $overrideArray;
     $diffArray = deepArrayDiff($this->config, $sugar_config);
     $overrideArray = sugarArrayMerge($overrideArray, $diffArray);
     $overideString = "<?php\n/***CONFIGURATOR***/\n";
     sugar_cache_put('sugar_config', $this->config);
     $GLOBALS['sugar_config'] = $this->config;
     foreach ($overrideArray as $key => $val) {
         if (in_array($key, $this->allow_undefined) || isset($sugar_config[$key])) {
             if (strcmp("{$val}", 'true') == 0) {
                 $val = true;
                 $this->config[$key] = $val;
             }
             if (strcmp("{$val}", 'false') == 0) {
                 $val = false;
                 $this->config[$key] = false;
             }
         }
         $overideString .= override_value_to_string_recursive2('sugar_config', $key, $val);
     }
     $overideString .= '/***CONFIGURATOR***/';
     $this->saveOverride($overideString);
     if (isset($this->config['logger']['level']) && $this->logger) {
         $this->logger->setLevel($this->config['logger']['level']);
     }
 }
Example #5
0
function override_value_to_string_recursive2($array_name, $value_name, $value, $save_empty = true)
{
    if (is_array($value)) {
        $str = '';
        $newArrayName = $array_name . "['{$value_name}']";
        foreach ($value as $key => $val) {
            $str .= override_value_to_string_recursive2($newArrayName, $key, $val, $save_empty);
        }
        return $str;
    } else {
        if (!$save_empty && empty($value)) {
            return;
        } else {
            return "\${$array_name}" . "['{$value_name}'] = " . var_export($value, true) . ";\n";
        }
    }
}
Example #6
0
 public function saveConfig()
 {
     $config_str = "<?php\n/***CONNECTOR SOURCE***/\n";
     foreach ($this->_config as $key => $val) {
         if (!empty($val)) {
             $config_str .= override_value_to_string_recursive2('config', $key, $val, false);
         }
     }
     $dir = str_replace('_', '/', get_class($this));
     if (!file_exists("custom/modules/Connectors/connectors/sources/{$dir}")) {
         mkdir_recursive("custom/modules/Connectors/connectors/sources/{$dir}");
     }
     $fp = sugar_fopen("custom/modules/Connectors/connectors/sources/{$dir}/config.php", 'w');
     fwrite($fp, $config_str);
     fclose($fp);
 }
Example #7
0
 function save($key_name, $duplicate = false, $rename = false)
 {
     $header = file_get_contents('modules/ModuleBuilder/MB/header.php');
     $save_path = $this->path . '/language';
     mkdir_recursive($save_path);
     foreach ($this->strings as $lang => $values) {
         //Check if the module Label has changed.
         $renameLang = $rename || empty($values) || isset($values['LBL_MODULE_NAME']) && $this->label != $values['LBL_MODULE_NAME'];
         $mod_strings = return_module_language(str_replace('.lang.php', '', $lang), 'ModuleBuilder');
         $required = array('LBL_LIST_FORM_TITLE' => $this->label . " " . $mod_strings['LBL_LIST'], 'LBL_MODULE_NAME' => $this->label, 'LBL_MODULE_TITLE' => $this->label, 'LBL_HOMEPAGE_TITLE' => $mod_strings['LBL_HOMEPAGE_PREFIX'] . " " . $this->label, 'LNK_NEW_RECORD' => $mod_strings['LBL_CREATE'] . " " . $this->label, 'LNK_LIST' => $mod_strings['LBL_VIEW'] . " " . $this->label, 'LNK_IMPORT_' . strtoupper($this->key_name) => translate('LBL_IMPORT') . " " . $this->label, 'LBL_SEARCH_FORM_TITLE' => $mod_strings['LBL_SEARCH'] . " " . $this->label, 'LBL_HISTORY_SUBPANEL_TITLE' => $mod_strings['LBL_HISTORY'], 'LBL_ACTIVITIES_SUBPANEL_TITLE' => $mod_strings['LBL_ACTIVITIES'], 'LBL_' . strtoupper($this->key_name) . '_SUBPANEL_TITLE' => $this->label, 'LBL_NEW_FORM_TITLE' => $mod_strings['LBL_NEW'] . " " . $this->label);
         foreach ($required as $k => $v) {
             if (empty($values[$k]) || $renameLang) {
                 $values[$k] = $v;
             }
         }
         write_array_to_file('mod_strings', $values, $save_path . '/' . $lang, 'w', $header);
     }
     $app_save_path = $this->path . '/../../language/application';
     mkdir_recursive($app_save_path);
     $key_changed = $this->key_name != $key_name;
     foreach ($this->appListStrings as $lang => $values) {
         // Load previously created modules data
         // $app_list_strings = array (); --- fix for issue #305
         $neededFile = $app_save_path . '/' . $lang;
         if (file_exists($neededFile)) {
             include $neededFile;
         }
         if (!$duplicate) {
             unset($values['moduleList'][$this->key_name]);
         }
         // $values = sugarLangArrayMerge($values, $app_list_strings); --- fix for issue #305
         $values['moduleList'][$key_name] = $this->label;
         $appFile = $header . "\n";
         require_once 'include/utils/array_utils.php';
         $this->getGlobalAppListStringsForMB($values);
         foreach ($values as $key => $array) {
             if ($duplicate) {
                 //keep the original when duplicating
                 $appFile .= override_value_to_string_recursive2('app_list_strings', $key, $array);
             }
             $okey = $key;
             if ($key_changed) {
                 $key = str_replace($this->key_name, $key_name, $key);
             }
             if ($key_changed) {
                 $key = str_replace(strtolower($this->key_name), strtolower($key_name), $key);
             }
             // if we aren't duplicating or the key has changed let's add it
             if (!$duplicate || $okey != $key) {
                 $appFile .= override_value_to_string_recursive2('app_list_strings', $key, $array);
             }
         }
         $fp = sugar_fopen($app_save_path . '/' . $lang, 'w');
         fwrite($fp, $appFile);
         fclose($fp);
     }
 }
Example #8
0
 function handleOverride($fromParseLoggerSettings = false)
 {
     global $sugar_config, $sugar_version;
     $sc = SugarConfig::getInstance();
     $overrideArray = $this->readOverride();
     $this->previous_sugar_override_config_array = $overrideArray;
     $diffArray = deepArrayDiff($this->config, $sugar_config);
     $overrideArray = sugarArrayMergeRecursive($overrideArray, $diffArray);
     // To remember checkbox state
     if (!$this->useAuthenticationClass && !$fromParseLoggerSettings) {
         if (isset($overrideArray['authenticationClass']) && $overrideArray['authenticationClass'] == 'SAMLAuthenticate') {
             unset($overrideArray['authenticationClass']);
         }
     }
     $overideString = "<?php\n/***CONFIGURATOR***/\n";
     sugar_cache_put('sugar_config', $this->config);
     $GLOBALS['sugar_config'] = $this->config;
     //print_r($overrideArray);
     //Bug#53013: Clean the tpl cache if action menu style has been changed.
     if (isset($overrideArray['enable_action_menu']) && (!isset($this->previous_sugar_override_config_array['enable_action_menu']) || $overrideArray['enable_action_menu'] != $this->previous_sugar_override_config_array['enable_action_menu'])) {
         require_once 'modules/Administration/QuickRepairAndRebuild.php';
         $repair = new RepairAndClear();
         $repair->module_list = array();
         $repair->clearTpls();
     }
     foreach ($overrideArray as $key => $val) {
         if (in_array($key, $this->allow_undefined) || isset($sugar_config[$key])) {
             if (is_string($val) && strcmp($val, 'true') == 0) {
                 $val = true;
                 $this->config[$key] = $val;
             }
             if (is_string($val) && strcmp($val, 'false') == 0) {
                 $val = false;
                 $this->config[$key] = false;
             }
         }
         $overideString .= override_value_to_string_recursive2('sugar_config', $key, $val);
     }
     $overideString .= '/***CONFIGURATOR***/';
     $this->saveOverride($overideString);
     if (isset($this->config['logger']['level']) && $this->logger) {
         $this->logger->setLevel($this->config['logger']['level']);
     }
 }
Example #9
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 ;
    }
Example #10
0
 /**
  * Update the metadata depending on what we are forecasting on
  *
  * @param String $forecast_by The Module that we are currently forecasting by
  */
 public function updateConfigWorksheetColumnsMetadata($forecast_by)
 {
     if ($forecast_by === 'RevenueLineItems') {
         $contents = "<?php\n\n";
         $key = "viewdefs['Forecasts']['base']['view']['config-worksheet-columns']['panels'][0]['fields']";
         foreach ($this->rli_worksheet_columns as $val) {
             $contents .= override_value_to_string_recursive2($key, $val['name'], $val, false);
         }
         sugar_file_put_contents($this->module_ext_path . DIRECTORY_SEPARATOR . $this->columns_ext_file, $contents);
     } else {
         if (SugarAutoLoader::fileExists($this->module_ext_path . DIRECTORY_SEPARATOR . $this->columns_ext_file)) {
             SugarAutoLoader::unlink($this->module_ext_path . DIRECTORY_SEPARATOR . $this->columns_ext_file);
         }
     }
     $this->runRebuildExtensions(array('Forecasts'));
     MetaDataManager::refreshModulesCache('Forecasts');
 }
Example #11
0
 function handleOverride($fromParseLoggerSettings = false)
 {
     global $sugar_config, $sugar_version;
     $sc = SugarConfig::getInstance();
     $overrideArray = $this->readOverride();
     $this->previous_sugar_override_config_array = $overrideArray;
     $diffArray = deepArrayDiff($this->config, $sugar_config);
     $overrideArray = sugarArrayMergeRecursive($overrideArray, $diffArray);
     // To remember checkbox state
     if (!$this->useAuthenticationClass && !$fromParseLoggerSettings) {
         if (isset($overrideArray['authenticationClass']) && $overrideArray['authenticationClass'] == 'SAMLAuthenticate') {
             unset($overrideArray['authenticationClass']);
         }
     }
     $overideString = "<?php\n/***CONFIGURATOR***/\n";
     sugar_cache_put('sugar_config', $this->config);
     $GLOBALS['sugar_config'] = $this->config;
     //print_r($overrideArray);
     foreach ($overrideArray as $key => $val) {
         if (in_array($key, $this->allow_undefined) || isset($sugar_config[$key])) {
             if (strcmp("{$val}", 'true') == 0) {
                 $val = true;
                 $this->config[$key] = $val;
             }
             if (strcmp("{$val}", 'false') == 0) {
                 $val = false;
                 $this->config[$key] = false;
             }
         }
         $overideString .= override_value_to_string_recursive2('sugar_config', $key, $val);
     }
     $overideString .= '/***CONFIGURATOR***/';
     $this->saveOverride($overideString);
     if (isset($this->config['logger']['level']) && $this->logger) {
         $this->logger->setLevel($this->config['logger']['level']);
     }
 }
Example #12
0
 /**
  * Scan extension directories for file with bad field definition.
  * @param SugarBean $seed
  * @param String $field
  */
 protected function removeFieldFromExt($seed, $field)
 {
     $mod = $seed->module_dir;
     $files = $this->getFiles($seed, '', $field);
     if (count($files) == 0) {
         return false;
     }
     foreach ($files as $file) {
         $dictionary = array();
         include $file;
         if (!empty($dictionary[$seed->object_name]['fields'][$field])) {
             $this->upgrader->backupFile($file);
             $this->log("Remove definition of {$field} for module {$mod}");
             $out = "<?php\n // created: " . date('Y-m-d H:i:s') . "\n";
             unset($dictionary[$seed->object_name]['fields'][$field]);
             if (empty($dictionary)) {
                 $this->deleteFile($file);
             } else {
                 foreach (array_keys($dictionary) as $key) {
                     $out .= override_value_to_string_recursive2('dictionary', $key, $dictionary[$key]);
                 }
                 file_put_contents($file, $out);
             }
         }
     }
     return true;
 }
Example #13
0
 /**
  * Get the config values encoded to string format to place into the custom modules directory
  * @param $key array key
  * @param $val array value
  */
 public function getConfigString($key, $val)
 {
     return override_value_to_string_recursive2('config', $key, $val, false);
 }
Example #14
0
 /**
  * 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 .= override_value_to_string_recursive2('config', $key, $val, false);
         }
     }
     $dir = str_replace('_', '/', get_class($this));
     if (!file_exists("custom/modules/Connectors/connectors/sources/{$dir}")) {
         mkdir_recursive("custom/modules/Connectors/connectors/sources/{$dir}");
     }
     file_put_contents("custom/modules/Connectors/connectors/sources/{$dir}/config.php", $config_str);
 }
Example #15
0
/**
 * Given an array name, key name and value of array, return a string of re-composed array.
 *
 * @param string $array_name : name of the array
 * @param string $value_name : name of the array keys
 * @param array $value : value of current array
 * @param boolean $save_empty : flag to allow save empty
 * @param array $original : original sugar_config array
 *
 * @return string : example - "\$sugar_config['a']['b']['c'][0] = 'hello';\n"
 */
function override_value_to_string_recursive2($array_name, $value_name, $value, $save_empty = true, $original = null)
{
    $quoted_vname = var_export($value_name, true);
    if (is_array($value)) {
        $str = '';
        $seq = false;
        $newArrayName = $array_name . "[{$quoted_vname}]";
        if (is_array($original)) {
            if (!empty($original[$value_name]) && is_array($original[$value_name])) {
                $original = $original[$value_name];
                $seq = is_sequential($original);
            } else {
                $original = array();
            }
        } else {
            $original = null;
        }
        foreach ($value as $key => $val) {
            $org = null;
            if (is_array($val) || $seq) {
                $org = $original;
            } else {
                if (is_array($original) && empty($original)) {
                    $org = array();
                }
            }
            $str .= override_value_to_string_recursive2($newArrayName, $key, $val, $save_empty, $org);
        }
        return $str;
    } else {
        if (!$save_empty && empty($value)) {
            return;
        } else {
            if (is_numeric($value_name)) {
                if ($original && !array_key_exists($value_name, $original)) {
                    return "\${$array_name}" . "[] = " . var_export($value, true) . ";\n";
                }
                if ($value_name === 0 && is_array($original) && empty($original)) {
                    return "\${$array_name}" . "[] = " . var_export($value, true) . ";\n";
                }
            }
            return "\${$array_name}" . "[{$quoted_vname}] = " . var_export($value, true) . ";\n";
        }
    }
}
 /**
  * Writes the config data to the custom file from whence it came
  *
  * @param array $config The config data to save
  * @param string $file The file name to save
  * @return int The amount of data saved to the file
  */
 public function saveUpdatedConfigFile($config, $file)
 {
     $write = "<?php\n/***CONNECTOR SOURCE***/\n";
     foreach ($config as $key => $val) {
         if (!empty($val)) {
             $write .= override_value_to_string_recursive2('config', $key, $val, false);
         }
     }
     return file_put_contents($file, $write);
 }
Example #17
0
 /**
  * Update file with new definition
  * @param string $file
  * @param array $var
  * @param string $varName
  */
 protected function updateFile($file, $var, $varName)
 {
     $this->upgrader->backupFile($file);
     $out = "<?php\n// created: ' . date('Y-m-d H:i:s')\n";
     foreach (array_keys($var) as $key) {
         $out .= override_value_to_string_recursive2($varName, $key, $var[$key]);
     }
     sugar_file_put_contents_atomic($file, $out);
 }
Example #18
0
 /**
  * Save labels that not need be uninstalled at this case
  * 
  * @param $filename
  * @param $stringsName
  * @param $strings
  */
 protected function saveContentToFile($filename, $stringsName, $strings)
 {
     $fileContent = "<?php\n//THIS FILE IS AUTO GENERATED, DO NOT MODIFY\n";
     foreach ($strings as $key => $val) {
         $fileContent .= override_value_to_string_recursive2($stringsName, $key, $val);
     }
     sugar_file_put_contents($filename, $fileContent);
 }
Example #19
0
 function save($key_name, $duplicate = false, $rename = false)
 {
     $header = file_get_contents('modules/ModuleBuilder/MB/header.php');
     $save_path = $this->path . '/language';
     mkdir_recursive($save_path);
     foreach ($this->strings as $lang => $values) {
         //Check if the module Label or Singular Label has changed.
         $mod_strings = return_module_language(str_replace('.lang.php', '', $lang), 'ModuleBuilder');
         $required = array('LBL_LIST_FORM_TITLE' => $this->label . " " . $mod_strings['LBL_LIST'], 'LBL_MODULE_NAME' => $this->label, 'LBL_MODULE_TITLE' => $this->label, 'LBL_MODULE_NAME_SINGULAR' => $this->label_singular, 'LBL_HOMEPAGE_TITLE' => $mod_strings['LBL_HOMEPAGE_PREFIX'] . " " . $this->label, 'LNK_NEW_RECORD' => $mod_strings['LBL_CREATE'] . " " . $this->label_singular, 'LNK_LIST' => $mod_strings['LBL_VIEW'] . " " . $this->label, 'LNK_IMPORT_' . strtoupper($this->key_name) => translate('LBL_IMPORT') . " " . $this->label_singular, 'LBL_SEARCH_FORM_TITLE' => $mod_strings['LBL_SEARCH'] . " " . $this->label_singular, 'LBL_HISTORY_SUBPANEL_TITLE' => $mod_strings['LBL_HISTORY'], 'LBL_ACTIVITIES_SUBPANEL_TITLE' => $mod_strings['LBL_ACTIVITIES'], 'LBL_' . strtoupper($this->key_name) . '_SUBPANEL_TITLE' => $this->label, 'LBL_NEW_FORM_TITLE' => $mod_strings['LBL_NEW'] . " " . $this->label_singular, 'LNK_IMPORT_VCARD' => translate('LBL_IMPORT') . " " . $this->label_singular . ' vCard', 'LBL_IMPORT' => translate('LBL_IMPORT') . " " . $this->label, 'LBL_IMPORT_VCARDTEXT' => "Automatically create a new {$this->label_singular} record by importing a vCard from your file system.");
         foreach ($required as $k => $v) {
             $values[$k] = $v;
         }
         write_array_to_file('mod_strings', $values, $save_path . '/' . $lang, 'w', $header);
     }
     $app_save_path = $this->path . '/../../language/application';
     sugar_mkdir($app_save_path, null, true);
     $key_changed = $this->key_name != $key_name;
     foreach ($this->appListStrings as $lang => $values) {
         // Load previously created modules data
         $app_list_strings = array();
         $neededFile = $app_save_path . '/' . $lang;
         if (file_exists($neededFile)) {
             include $neededFile;
         }
         if (!$duplicate) {
             unset($values['moduleList'][$this->key_name]);
         }
         $values = sugarLangArrayMerge($values, $app_list_strings);
         $values['moduleList'][$key_name] = $this->label;
         $values['moduleListSingular'][$key_name] = $this->label_singular;
         $appFile = $header . "\n";
         require_once 'include/utils/array_utils.php';
         $this->getGlobalAppListStringsForMB($values);
         foreach ($values as $key => $array) {
             if ($duplicate) {
                 //keep the original when duplicating
                 $appFile .= override_value_to_string_recursive2('app_list_strings', $key, $array);
             }
             $okey = $key;
             if ($key_changed) {
                 $key = str_replace(strtolower($this->key_name), strtolower($key_name), $key);
             }
             // if we aren't duplicating or the key has changed let's add it
             if (!$duplicate || $okey != $key) {
                 if ($rename && isset($this->appListStrings[$lang][$key])) {
                     $arr = $this->appListStrings[$lang][$key];
                 } else {
                     $arr = $array;
                 }
                 $appFile .= override_value_to_string_recursive2('app_list_strings', $key, $arr);
             }
         }
         sugar_file_put_contents_atomic($app_save_path . '/' . $lang, $appFile);
     }
 }
 protected function saveLabels($basepath, $installDefPrefix, $relationshipName, $labelDefinitions)
 {
     global $sugar_config;
     mkdir_recursive("{$basepath}/language");
     $headerString = "<?php\n//THIS FILE IS AUTO GENERATED, DO NOT MODIFY\n";
     $installDefs = array();
     foreach ($labelDefinitions as $definition) {
         $mod_strings = array();
         $app_list_strings = array();
         $out = $headerString;
         $filename = "{$basepath}/language/{$definition['module']}.php";
         if (file_exists($filename)) {
             include $filename;
         }
         //Check for app strings
         $GLOBALS['log']->debug(get_class($this) . "->saveLabels(): saving the following to {$filename}" . print_r($definition, true));
         if ($definition['module'] == 'application') {
             $app_list_strings[$definition['system_label']] = $definition['display_label'];
             foreach ($app_list_strings as $key => $val) {
                 $out .= override_value_to_string_recursive2('app_list_strings', $key, $val);
             }
         } else {
             $mod_strings[$definition['system_label']] = $definition['display_label'];
             foreach ($mod_strings as $key => $val) {
                 $out .= override_value_to_string_recursive2('mod_strings', $key, $val);
             }
         }
         $fh = fopen($filename, 'w');
         fputs($fh, $out, strlen($out));
         fclose($fh);
         foreach ($sugar_config['languages'] as $lk => $lv) {
             $installDefs[$definition['module'] . "_{$lk}"] = array('from' => "{$installDefPrefix}/relationships/language/{$definition['module']}.php", 'to_module' => $definition['module'], 'language' => $lk);
         }
         /* do not use the following write_array_to_file method to write the label file - 
          * module installer appends each of the label files together (as it does for all files) 
          * into a combined label file and so the last $mod_strings is the only one received by the application */
         // write_array_to_file ( 'mod_strings', array ( $definition [ 'system_label' ] => $definition [ 'display_label' ] ), $filename, "a" ) ;
     }
     return $installDefs;
 }
 protected function saveLabels($basepath, $installDefPrefix, $relationshipName, $labelDefinitions)
 {
     global $sugar_config;
     mkdir_recursive("{$basepath}/language");
     $headerString = "<?php\n//THIS FILE IS AUTO GENERATED, DO NOT MODIFY\n";
     $installDefs = array();
     $moduleLabels = array();
     foreach ($labelDefinitions as $definition) {
         $moduleLabels[$definition['module']][$definition['system_label']] = $definition['display_label'];
     }
     foreach ($moduleLabels as $module => $labels) {
         $out = $headerString;
         $filename = "{$basepath}/language/{$module}.php";
         $mod_strings = array();
         $app_list_strings = array();
         if (file_exists($filename)) {
             include $filename;
         }
         if ($module == 'application') {
             $varName = 'app_list_strings';
             $languageStrings = $app_list_strings;
         } else {
             $varName = 'mod_strings';
             $languageStrings = $mod_strings;
         }
         //Check for app strings
         $GLOBALS['log']->debug(get_class($this) . "->saveLabels(): saving the following to {$filename}" . print_r($labels, true));
         $languageStrings = array_merge($languageStrings, $labels);
         foreach ($languageStrings as $key => $value) {
             $out .= override_value_to_string_recursive2($varName, $key, $value);
         }
         sugar_file_put_contents($filename, $out);
         foreach ($sugar_config['languages'] as $lk => $lv) {
             $installDefs[$module . "_{$lk}"] = array('from' => "{$installDefPrefix}/relationships/language/{$module}.php", 'to_module' => $module, 'language' => $lk);
         }
     }
     return $installDefs;
 }