public function run()
 {
     if (!version_compare($this->from_version, '7.0', '>') || !version_compare($this->from_version, '7.6', '<')) {
         // only need to run this upgrading for greater than 7.0 and less than 7.7
         return;
     }
     $customModules = $this->getCustomModules();
     if (empty($customModules)) {
         // No MB modules - nothing to do
         return;
     }
     foreach ($customModules as $module) {
         $path = 'modules/' . $module . '/clients/base/menus/header/header.php';
         $this->foundPattern = false;
         $viewdefs = null;
         include $path;
         if (!empty($viewdefs)) {
             $module = key($viewdefs);
             $array = $viewdefs[$module]['base']['menu']['header'];
             $this->fixIcons($array);
             if ($this->foundPattern) {
                 sugar_file_put_contents($path, "<?php\n\n/* This file was generated by the 7_FixIconNameChanges upgrader */\n\$viewdefs['{$module}']['base']['menu']['header'] =  " . var_export($array, true) . ";\n");
             }
         }
         $viewdefs = null;
     }
 }
 public function setUp()
 {
     $this->authclassname = 'TestAuthClass' . mt_rand();
     sugar_mkdir("custom/modules/Users/authentication/{$this->authclassname}/", null, true);
     sugar_file_put_contents("custom/modules/Users/authentication/{$this->authclassname}/{$this->authclassname}.php", "<?php\nrequire_once 'modules/Users/authentication/SugarAuthenticate/SugarAuthenticate.php';\nclass {$this->authclassname} extends SugarAuthenticate {\n    public \$userAuthenticateClass = '{$this->authclassname}User';\n    public \$authenticationDir = '{$this->authclassname}';\n\n    public function _construct(){\n\t    parent::SugarAuthenticate();\n\t}\n}");
     sugar_file_put_contents("custom/modules/Users/authentication/{$this->authclassname}/{$this->authclassname}User.php", "<?php\nrequire_once 'modules/Users/authentication/SugarAuthenticate/SugarAuthenticateUser.php';\nclass {$this->authclassname}User extends SugarAuthenticateUser {\n}");
 }
 /**
  * Save a dictionary for a particular API to storage
  * @internal
  * @param string $apiType The api type for the dictionary you want to load ("Rest" or "Soap")
  * @param array $storageData The data that the API needs to store for it's dictionary.
  */
 protected function saveDictionaryToStorage($apiType, $storageData)
 {
     if (!is_dir($this->cacheDir)) {
         sugar_mkdir($this->cacheDir, null, true);
     }
     sugar_file_put_contents($this->cacheDir . 'ServiceDictionary.' . $apiType . '.php', '<' . "?php\n\$apiDictionary['" . $apiType . "'] = " . var_export($storageData, true) . ";\n");
 }
    public function run()
    {
        $path = 'custom/Extension/application/Ext';
        $file_name = 'project_unhide.php';
        if (version_compare($this->to_version, '7.2.2.0', '=') && SugarAutoLoader::fileExists($path . '/Include/' . $file_name)) {
            $file_contents = '
<?php
// WARNING: The contents of this file are auto-generated.

$moduleList[] = \'Project\';
$moduleList[] = \'ProjectTask\';

if (isset($modInvisList) && is_array($modInvisList)) {
    foreach($modInvisList as $key => $mod) {
        if($mod == \'Project\' || $mod == \'ProjectTask\') {
            unset($modInvisList[$key]);
        }
    }
}
';
            // enable the project module in the upgrade instance
            global $moduleList, $modInvisList;
            $moduleList[] = 'ProjectTask';
            foreach ($modInvisList as $key => $mod) {
                if ($mod == 'Project' || $mod == 'ProjectTask') {
                    unset($modInvisList[$key]);
                }
            }
            sugar_file_put_contents($path . '/Include/' . $file_name, $file_contents);
        }
    }
Example #5
0
function post_install()
{
    // Include existing custom entry point registry array
    @(include_once 'custom/include/MVC/Controller/entry_point_registry.php');
    // Start building custom entry point PHP
    $the_string = "<?php\n" . '// created: ' . date('Y-m-d H:i:s') . "\n\n";
    // Define new entry point
    $entry_point_registry['AsteriskController'] = array('file' => 'custom/modules/Asterisk/include/controller.php', 'auth' => true);
    $entry_point_registry['AsteriskCallListener'] = array('file' => 'custom/modules/Asterisk/include/callListener.php', 'auth' => true);
    $entry_point_registry['AsteriskCallCreate'] = array('file' => 'custom/modules/Asterisk/include/callCreate.php', 'auth' => true);
    // For each custom entry point, add override value
    foreach ($entry_point_registry as $key => $value) {
        $the_string .= override_value_to_string('entry_point_registry', $key, $value) . "\n";
    }
    // Write the dir if needed
    if (!is_dir('custom/include/MVC/Controller')) {
        $result = sugar_mkdir('custom/include/MVC/Controller', NULL, true);
    }
    // Write the new custom entry point registry file
    $result = @sugar_file_put_contents('custom/include/MVC/Controller/entry_point_registry.php', $the_string);
    if ($_REQUEST['mode'] == 'Install') {
        ?>
<br /><br />
<span style="font-size: 2em;"><strong>Please review the documentation!  There are several additional steps that must be taken.</strong></span> 
<br /><span style="font-size: 1.3em;">The User Guide can be found on the Project website here: <a href="https://github.com/blak3r/yaai/wiki/User-Manual">https://github.com/blak3r/yaai/wiki/User-Manual</a></span>

<?php 
    }
}
Example #6
0
 public function testGetMetaDataFile()
 {
     // backup custom file if it already exists
     if (file_exists('custom/modules/Contacts/metadata/listviewdefs.php')) {
         copy('custom/modules/Contacts/metadata/listviewdefs.php', 'custom/modules/Contacts/metadata/listviewdefs.php.bak');
         unlink('custom/modules/Contacts/metadata/listviewdefs.php');
     }
     $this->_view->module = 'Contacts';
     $this->_view->type = 'list';
     $metaDataFile = $this->_view->getMetaDataFile();
     $this->assertEquals('modules/Contacts/metadata/listviewdefs.php', $metaDataFile, 'Did not load the correct metadata file');
     //test custom file
     if (!file_exists('custom/modules/Contacts/metadata/')) {
         sugar_mkdir('custom/modules/Contacts/metadata/', null, true);
     }
     $customFile = 'custom/modules/Contacts/metadata/listviewdefs.php';
     if (!file_exists($customFile)) {
         sugar_file_put_contents($customFile, array());
         $customMetaDataFile = $this->_view->getMetaDataFile();
         $this->assertEquals($customFile, $customMetaDataFile, 'Did not load the correct custom metadata file');
         unlink($customFile);
     }
     // Restore custom file if we backed it up
     if (file_exists('custom/modules/Contacts/metadata/listviewdefs.php.bak')) {
         rename('custom/modules/Contacts/metadata/listviewdefs.php.bak', 'custom/modules/Contacts/metadata/listviewdefs.php');
     }
 }
Example #7
0
 public function setUp()
 {
     $this->_has_initial_server_port = isset($_SERVER['SERVER_PORT']);
     if ($this->_has_initial_server_port) {
         $this->_initial_server_port = $_SERVER['SERVER_PORT'];
     }
     sugar_file_put_contents($this->_cron_test_file, "<?php echo 'Hello World!';");
 }
 /**
  * Check if semi-colon separated non-primary mails
  * are being imported properly
  *
  * @dataProvider providerEmailImport
  */
 public function testEmailImport($module, $lastName, $expected, $test)
 {
     $fileCreated = sugar_file_put_contents($this->_file, $test);
     $this->assertGreaterThan(0, $fileCreated, 'Failed to write to ' . $this->_file);
     // Create the ImportFile the Importer uses from our CSV
     $importSource = new ImportFile($this->_file, ',', '"');
     // Create the bean type we're importing
     $this->_importObject = $bean = new $module();
     // Setup needed $_REQUEST data
     $_REQUEST['columncount'] = 2;
     $_REQUEST['colnum_0'] = 'email_addresses_non_primary';
     $_REQUEST['colnum_1'] = 'last_name';
     // A few changed for Accounts module
     if ($module == "Account") {
         $_REQUEST['columncount'] = 3;
         $_REQUEST['colnum_1'] = 'name';
         $_REQUEST['colnum_2'] = 'team_id';
     }
     $_REQUEST['import_module'] = $bean->module_dir;
     $_REQUEST['importlocale_charset'] = 'UTF-8';
     $_REQUEST['importlocale_dateformat'] = "m/d/Y";
     $_REQUEST['importlocale_timeformat'] = "h:i a";
     $_REQUEST['importlocale_timezone'] = 'GMT';
     $_REQUEST['importlocale_default_currency_significant_digits'] = '2';
     $_REQUEST['importlocale_currency'] = '-99';
     $_REQUEST['importlocale_dec_sep'] = '.';
     $_REQUEST['importlocale_currency'] = '-99';
     $_REQUEST['importlocale_default_locale_name_format'] = 's f l';
     $_REQUEST['importlocale_num_grp_sep'] = ',';
     // Create the Importer and try importing
     $importer = new Importer($importSource, $bean);
     $importer->import();
     // Check if the Lead is created
     $query = "SELECT id FROM {$bean->table_name} WHERE {$_REQUEST['colnum_1']} = '{$lastName}'";
     $result = $GLOBALS['db']->query($query);
     $row = $GLOBALS['db']->fetchByAssoc($result);
     $this->assertNotEmpty($row['id'], $module . ' not created');
     // Save Lead id for easier cleanup after test
     $this->_cleanId = $row['id'];
     // Check if all of the mails got created and linked properly
     foreach ($expected as $mail) {
         // Check if the mail got created
         $query = "SELECT id FROM email_addresses WHERE email_address = '{$mail}'";
         $result = $GLOBALS['db']->query($query);
         $row = $GLOBALS['db']->fetchByAssoc($result);
         $this->assertNotEmpty($row['id'], 'Mail not created');
         $mailId = $row['id'];
         // Check if the mail is linked
         $query = "SELECT id FROM email_addr_bean_rel WHERE email_address_id = '{$mailId}' AND bean_module = '{$bean->module_dir}' AND deleted = 0 AND primary_address = 0";
         $result = $GLOBALS['db']->query($query);
         $row = $GLOBALS['db']->fetchByAssoc($result);
         $this->assertNotEmpty($row['id'], 'Mail not linked');
     }
 }
 public function run()
 {
     foreach (glob('custom/themes/clients/*/*/variables.less') as $customTheme) {
         $path = pathinfo($customTheme, PATHINFO_DIRNAME);
         $variables = $this->parseFile($path . '/variables.less');
         // Convert to new defs
         $lessdefs = array('colors' => $variables['hex']);
         // Write new defs
         $write = "<?php\n" . '// created: ' . date('Y-m-d H:i:s') . "\n" . '$lessdefs = ' . var_export_helper($lessdefs) . ';';
         sugar_file_put_contents($path . '/variables.php', $write);
         // Delete old defs
         $this->fileToDelete($path . '/variables.less');
     }
 }
Example #10
0
 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 #11
0
 public function testGetMetaDataFile()
 {
     $this->_view->module = 'Contacts';
     $this->_view->type = 'list';
     $metaDataFile = $this->_view->getMetaDataFile();
     $this->assertEquals('modules/Contacts/metadata/listviewdefs.php', $metaDataFile, 'Did not load the correct metadata file');
     //test custom file
     sugar_mkdir('custom/modules/Contacts/metadata/', null, true);
     $customFile = 'custom/modules/Contacts/metadata/listviewdefs.php';
     if (!file_exists($customFile)) {
         sugar_file_put_contents($customFile, array());
         $customMetaDataFile = $this->_view->getMetaDataFile();
         $this->assertEquals($customFile, $customMetaDataFile, 'Did not load the correct custom metadata file');
         unlink($customFile);
     }
 }
 public function run()
 {
     // if we are coming from anything newer than 7, just bail
     if (version_compare($this->from_version, '7.0.0', '>')) {
         return;
     }
     if (!SugarAutoLoader::fileExists($this->file)) {
         # if we don't have a custom file, then bail
         return;
     }
     $viewdefs = null;
     include $this->file;
     if (!empty($viewdefs)) {
         $viewdefs = $this->fixFieldName($viewdefs);
         sugar_file_put_contents($this->file, "<?php\n\n \$viewdefs = " . var_export($viewdefs, true) . ";\n");
     }
     $viewdefs = null;
 }
Example #13
0
function post_install()
{
    // Include existing custom entry point registry array
    @(include_once 'custom/include/MVC/Controller/entry_point_registry.php');
    // Start building custom entry point PHP
    $the_string = "<?php\n" . '// created: ' . date('Y-m-d H:i:s') . "\n\n";
    // Define new entry point
    $entry_point_registry['AsteriskController'] = array('file' => 'custom/modules/Asterisk/include/controller.php', 'auth' => true);
    $entry_point_registry['AsteriskCallListener'] = array('file' => 'custom/modules/Asterisk/include/callListener.php', 'auth' => true);
    $entry_point_registry['AsteriskCallCreate'] = array('file' => 'custom/modules/Asterisk/include/callCreate.php', 'auth' => true);
    // For each custom entry point, add override value
    foreach ($entry_point_registry as $key => $value) {
        $the_string .= override_value_to_string('entry_point_registry', $key, $value) . "\n";
    }
    // Write the dir if needed
    if (!is_dir('custom/include/MVC/Controller')) {
        $result = sugar_mkdir('custom/include/MVC/Controller', NULL, true);
    }
    // Write the new custom entry point registry file
    $result = @sugar_file_put_contents('custom/include/MVC/Controller/entry_point_registry.php', $the_string);
    if ($_REQUEST['mode'] == 'Install') {
        ?>
<br /><br />
<span style="font-size: 1.6em;"><strong>Please review the documentation!  There are several additional steps that must be taken.</strong></span>
<br /><span style="font-size: 1.3em;">The User Guide can be found on the Project website here: <a href="https://github.com/blak3r/yaai/wiki/User-Manual">https://github.com/blak3r/yaai/wiki/User-Manual</a>.  Please note the fairly comprehensive troubleshooting section at the end of the manual.</span>
<br>
<BR>
<span style="font-size: 1.6em;"><strong>Donate to YAAI</strong></span>
<br /><span style="font-size:1.3em;">Please consider making a donation to the project.  Your contribution allows me to spend more time improving/supporting.
We're also in great need of some help from developers.  Please see: <a href="https://github.com/blak3r/yaai/wiki/Project-TODO-List">https://github.com/blak3r/yaai/wiki/Project-TODO-List</a> for ways you can help.</span>
<P>
    <BR/>
  <form action="https://www.paypal.com/cgi-bin/webscr" method="post">
      <input type="hidden" name="cmd" value="_s-xclick">
      <input type="hidden" name="hosted_button_id" value="FA36DGSYQ3NE6">
      <input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_donate_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
      <img alt="" border="0" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1">
  </form>
</P>

<?php 
    }
}
 public function handleSave()
 {
     if (empty($this->sidecarViewdefs)) {
         return true;
     }
     if ($this->isExt) {
         $newExtLocation = "custom/Extension/modules/{$this->module}/Ext/clients/base/menus/header/";
         if (!is_dir($newExtLocation)) {
             sugar_mkdir($newExtLocation, null, true);
         }
         $content = "<?php \n";
         foreach ($this->sidecarViewdefs as $menuItem) {
             $content .= "\${$this->menuName}[] = " . var_export($menuItem, true) . ";\n";
         }
         return sugar_file_put_contents($newExtLocation . "/" . $this->filename, $content);
     } elseif ($this->basename === 'globalControlLinks') {
         return $this->handleSaveArray($this->menuName, "custom/clients/base/views/profileactions/profileactions.php");
     } else {
         return $this->handleSaveArray($this->menuName, "custom/modules/{$this->module}/clients/base/menus/header/header.php");
     }
 }
 public function run()
 {
     if (version_compare($this->from_version, '7.0', '<') || version_compare($this->from_version, '7.2', '>=')) {
         // only need to run this upgrading from 7.0 - 7.2
         return;
     }
     foreach (glob('custom/modules/*/clients/base/views/record/record.php') as $recordFile) {
         $this->foundPattern = false;
         $viewdef = null;
         include $recordFile;
         if (!empty($viewdefs)) {
             $module = key($viewdefs);
             $array = $viewdefs[$module]['base']['view']['record'];
             $this->fixLabels($array);
             if ($this->foundPattern) {
                 $this->log("Removing Smarty labels from file {$recordFile}");
                 sugar_file_put_contents($recordFile, "<?php\n\n/* This file was generated by the 7_UpdateCustomBrokenViewLabels upgrader */\n\$viewdefs['{$module}']['base']['view']['record'] =  " . var_export($array, true) . ";\n");
             }
         }
         $viewdefs = null;
     }
 }
Example #16
0
 public function setup()
 {
     $this->_moduleName = 'TestModuleForDashletLoadLanguageTest' . mt_rand();
     sugar_mkdir("custom/modules/{$this->_moduleName}/metadata/", null, true);
     sugar_file_put_contents("custom/modules/{$this->_moduleName}/metadata/dashletviewdefs.php", '<?php $dashletData[\'' . $this->_moduleName . 'Dashlet\'][\'searchFields\'] = array(); $dashletData[\'' . $this->_moduleName . 'Dashlet\'][\'columns\'] = array(\'Foo\'); ?>');
 }
Example #17
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);
 }
 protected function saveSubpanelDefinitions($basepath, $installDefPrefix, $relationshipName, $subpanelDefinitions)
 {
     mkdir_recursive("{$basepath}/layoutdefs/");
     foreach ($subpanelDefinitions as $moduleName => $definitions) {
         $filename = "{$basepath}/layoutdefs/{$relationshipName}_{$moduleName}.php";
         $subpanelVarname = 'layout_defs["' . $moduleName . '"]["subpanel_setup"]';
         $out = "";
         foreach ($definitions as $definition) {
             $GLOBALS['log']->debug(get_class($this) . "->saveSubpanelDefinitions(): saving the following to {$filename}" . print_r($definition, true));
             if (empty($definition['get_subpanel_data']) || $definition['subpanel_name'] == 'history' || $definition['subpanel_name'] == 'activities') {
                 $definition['get_subpanel_data'] = $definition['subpanel_name'];
             }
             $out .= override_value_to_string($subpanelVarname, strtolower($definition['get_subpanel_data']), $definition) . "\n";
         }
         if (!empty($out)) {
             $out = "<?php\n // created: " . date('Y-m-d H:i:s') . "\n" . $out;
             sugar_file_put_contents($filename, $out);
         }
         $installDefs[$moduleName] = array('from' => "{$installDefPrefix}/relationships/layoutdefs/{$relationshipName}_{$moduleName}.php", 'to_module' => $moduleName);
     }
     return $installDefs;
 }
Example #19
0
 /**
  * Returns the URL for an image in the current theme. If not found in the current theme, will revert
  * to looking in the base theme.
  *
  * @param  string $jsFileName js file name
  * @param  bool   $returnURL if true, returns URL with unique image mark, otherwise returns path to the file
  * @return string path to js file
  */
 public function getJSURL($jsFileName, $returnURL = true)
 {
     if (isset($this->_jsCache[$jsFileName]) && sugar_is_file(sugar_cached($this->_jsCache[$jsFileName]))) {
         if ($returnURL) {
             return getJSPath("cache/" . $this->_jsCache[$jsFileName]);
         } else {
             return sugar_cached($this->_jsCache[$jsFileName]);
         }
     }
     $jsFileContents = '';
     $fullFileName = $this->getJSPath() . '/' . $jsFileName;
     $defaultFileName = $this->getDefaultJSPath() . '/' . $jsFileName;
     if (isset($this->parentTheme) && SugarThemeRegistry::get($this->parentTheme) instanceof SugarTheme && ($filename = SugarThemeRegistry::get($this->parentTheme)->getJSURL($jsFileName, false)) != '' && !in_array($jsFileName, $this->ignoreParentFiles)) {
         $jsFileContents .= file_get_contents($filename);
     } else {
         if (sugar_is_file($defaultFileName)) {
             $jsFileContents .= file_get_contents($defaultFileName);
         }
         if (sugar_is_file('custom/' . $defaultFileName)) {
             $jsFileContents .= file_get_contents('custom/' . $defaultFileName);
         }
     }
     if (sugar_is_file($fullFileName)) {
         $jsFileContents .= file_get_contents($fullFileName);
     }
     if (sugar_is_file('custom/' . $fullFileName)) {
         $jsFileContents .= file_get_contents('custom/' . $fullFileName);
     }
     if (empty($jsFileContents)) {
         $GLOBALS['log']->warn("Javascript File {$jsFileName} not found");
         return false;
     }
     // create the cached file location
     $jsFilePath = create_cache_directory($fullFileName);
     // minify the js
     if (!inDeveloperMode() && !sugar_is_file(str_replace('.js', '-min.js', $jsFilePath))) {
         $jsFileContents = SugarMin::minify($jsFileContents);
         $jsFilePath = str_replace('.js', '-min.js', $jsFilePath);
         $fullFileName = str_replace('.js', '-min.js', $fullFileName);
     }
     // now write the js to cache
     sugar_file_put_contents($jsFilePath, $jsFileContents);
     $this->_jsCache[$jsFileName] = $fullFileName;
     if ($returnURL) {
         return getJSPath("cache/" . $fullFileName);
     }
     return sugar_cached($fullFileName);
 }
function write_array_to_file($the_name, $the_array, $the_file, $mode = "w", $header = '')
{
    if (!empty($header) && ($mode != 'a' || !file_exists($the_file))) {
        $the_string = $header;
    } else {
        $the_string = "<?php\n" . '// created: ' . date('Y-m-d H:i:s') . "\n";
    }
    $the_string .= "\${$the_name} = " . var_export_helper($the_array) . ";";
    return sugar_file_put_contents($the_file, $the_string, LOCK_EX) !== false;
}
Example #21
0
 * If you do not agree to all of the applicable terms or do not have the
 * authority to bind the entity as an authorized representative, then do not
 * install or use this SugarCRM file.
 *
 * Copyright (C) SugarCRM Inc. All rights reserved.
 */
require "include/modules.php";
require_once "include/utils/sugar_file_utils.php";
foreach ($beanFiles as $classname => $filename) {
    if (file_exists($filename)) {
        // Rename the class and its constructor adding SugarCore at the beginning  (Ex: class SugarCoreCall)
        $handle = file_get_contents($filename);
        $patterns = array('/class ' . $classname . '/', '/function ' . $classname . '/');
        $replace = array('class SugarCore' . $classname, 'function SugarCore' . $classname);
        $data = preg_replace($patterns, $replace, $handle);
        sugar_file_put_contents($filename, $data);
        // Rename the SugarBean file into SugarCore.SugarBean (Ex: SugarCore.Call.php)
        $pos = strrpos($filename, "/");
        $newfilename = substr_replace($filename, 'SugarCore.', $pos + 1, 0);
        sugar_rename($filename, $newfilename);
        //Create a new SugarBean that extends CoreBean
        $fileHandle = sugar_fopen($filename, 'w');
        $newclass = <<<FABRICE
<?php
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
/*
 * Your installation or use of this SugarCRM file is subject to the applicable
 * terms available at
 * http://support.sugarcrm.com/06_Customer_Center/10_Master_Subscription_Agreements/.
 * If you do not agree to all of the applicable terms or do not have the
 * authority to bind the entity as an authorized representative, then do not
 protected function buildRelationshipCache()
 {
     global $beanList, $dictionary, $buildingRelCache;
     if ($buildingRelCache) {
         return;
     }
     $buildingRelCache = true;
     include_once "modules/TableDictionary.php";
     if (empty($beanList)) {
         include "include/modules.php";
     }
     //Reload ALL the module vardefs....
     foreach ($beanList as $moduleName => $beanName) {
         VardefManager::loadVardef($moduleName, BeanFactory::getObjectName($moduleName));
     }
     $relationships = array();
     //Grab all the relationships from the dictionary.
     foreach ($dictionary as $key => $def) {
         if (!empty($def['relationships'])) {
             foreach ($def['relationships'] as $relKey => $relDef) {
                 if ($key == $relKey) {
                     //Relationship only entry, we need to capture everything
                     $relationships[$key] = array_merge(array('name' => $key), $def, $relDef);
                 } else {
                     $relationships[$relKey] = array_merge(array('name' => $relKey), $relDef);
                     if (!empty($relationships[$relKey]['join_table']) && empty($relationships[$relKey]['fields']) && isset($dictionary[$relationships[$relKey]['join_table']]['fields'])) {
                         $relationships[$relKey]['fields'] = $dictionary[$relationships[$relKey]['join_table']]['fields'];
                     }
                 }
             }
         }
     }
     //Save it out
     sugar_mkdir(dirname($this->getCacheFile()), null, true);
     $out = "<?php \n \$relationships=" . var_export($relationships, true) . ";";
     sugar_file_put_contents($this->getCacheFile(), $out);
     $this->relationships = $relationships;
     $buildingRelCache = false;
 }
 public function testDefaultThemedefFileHandled()
 {
     create_custom_directory('themes/default/');
     sugar_file_put_contents('custom/themes/default/themedef.php', '<?php $themedef = array("group_tabs" => false);');
     SugarThemeRegistry::buildRegistry();
     $this->assertEquals(SugarThemeRegistry::get($this->_themeName)->group_tabs, false);
     unlink('custom/themes/default/themedef.php');
 }
 protected function _saveToFile($filename, $defs, $useVariables = true, $forPopup = false)
 {
     if (file_exists($filename)) {
         unlink($filename);
     }
     mkdir_recursive(dirname($filename));
     $useVariables = count($this->_variables) > 0 && $useVariables;
     // only makes sense to do the variable replace if we have variables to replace...
     // create the new metadata file contents, and write it out
     $out = "<?php\n";
     if ($useVariables) {
         // write out the $<variable>=<modulename> lines
         foreach ($this->_variables as $key => $value) {
             $out .= "\${$key} = '" . $value . "';\n";
         }
     }
     $viewVariable = $this->_fileVariables[$this->_view];
     if ($forPopup) {
         $out .= "\${$viewVariable} = \n" . var_export_helper($defs);
     } else {
         $out .= "\${$viewVariable} [" . ($useVariables ? '$module_name' : "'{$this->_moduleName}'") . "] = \n" . var_export_helper($defs);
     }
     $out .= ";\n?>\n";
     if (sugar_file_put_contents($filename, $out) === false) {
         $GLOBALS['log']->fatal(get_class($this) . ": could not write new viewdef file " . $filename);
     }
 }
Example #25
0
 /**
  * Returns the URL for an image in the current theme. If not found in the current theme, will revert
  * to looking in the base theme.
  * 
  * @param  string $jsFileName js file name
  * @param  bool   $addJSPath call getJSPath() with the results to add some unique image tracking support
  * @return string path to js file
  */
 public function getJSURL($jsFileName, $addJSPath = true)
 {
     if (isset($this->_jsCache[$jsFileName])) {
         if ($addJSPath) {
             return getJSPath($this->_jsCache[$jsFileName]);
         } else {
             return $this->_jsCache[$jsFileName];
         }
     }
     $jsFileContents = '';
     if (isset($this->parentTheme) && SugarThemeRegistry::get($this->parentTheme) instanceof SugarTheme && ($filename = SugarThemeRegistry::get($this->parentTheme)->getJSURL($jsFileName, false)) != '') {
         $jsFileContents .= file_get_contents($filename);
     } else {
         if (sugar_is_file($this->getDefaultJSPath() . '/' . $jsFileName)) {
             $jsFileContents .= file_get_contents($this->getDefaultJSPath() . '/' . $jsFileName);
         }
         if (sugar_is_file('custom/' . $this->getDefaultJSPath() . '/' . $jsFileName)) {
             $jsFileContents .= file_get_contents('custom/' . $this->getDefaultJSPath() . '/' . $jsFileName);
         }
     }
     if (sugar_is_file($this->getJSPath() . '/' . $jsFileName)) {
         $jsFileContents .= file_get_contents($this->getJSPath() . '/' . $jsFileName);
     }
     if (sugar_is_file('custom/' . $this->getJSPath() . '/' . $jsFileName)) {
         $jsFileContents .= file_get_contents('custom/' . $this->getJSPath() . '/' . $jsFileName);
     }
     if (empty($jsFileContents)) {
         $GLOBALS['log']->warn("Javascript File {$jsFileName} not found");
         return false;
     }
     // create the cached file location
     $jsFilePath = create_cache_directory($this->getJSPath() . "/{$jsFileName}");
     // now write the js to cache
     sugar_file_put_contents($jsFilePath, $jsFileContents);
     // minify the js
     $jsFilePathMin = str_replace('.js', '-min.js', $jsFilePath);
     if (!inDeveloperMode() && !sugar_is_file($jsFilePathMin)) {
         $jMin = new JSMin($jsFilePath, $jsFilePathMin);
         $jMin->minify();
         $jsFilePath = $jsFilePathMin;
     }
     $this->_jsCache[$jsFileName] = $jsFilePath;
     if ($addJSPath) {
         return getJSPath($jsFilePath);
     }
     return $jsFilePath;
 }
Example #26
0
 /**
  * Scan directory and replace vendors links
  * @param string $path
  * @param array $directories
  * @return array Files data
  */
 public function scanDir($path, array $directories)
 {
     if (file_exists($path)) {
         $iter = new FilesystemIterator($path, FilesystemIterator::UNIX_PATHS);
         foreach ($iter as $item) {
             $filename = $item->getFilename();
             if ($filename == '.' || $filename == '..') {
                 continue;
             }
             if (strpos($filename, ".suback.php") !== false) {
                 // we'll ignore .suback files, they are old upgrade backups
                 continue;
             }
             if ($item->isDir() && in_array($filename, $this->excludedScanDirectories)) {
                 continue;
             } elseif ($item->isDir()) {
                 if (strtolower($filename) == 'disable' || strtolower($filename) == 'disabled') {
                     // skip disable dirs
                     continue;
                 }
                 $this->scanDir($path . $filename . "/", $directories);
             } elseif ($item->getExtension() != 'php') {
                 continue;
             } else {
                 if ($item->isFile()) {
                     $file = $item->getPathname();
                     $this->repairSugarSpecificFilesPath($file);
                     // check for any occurrence of the directories and replace them
                     $fileContents = file_get_contents($file);
                     foreach ($directories as $pattern => $replace) {
                         if (preg_match("#(include|require|require_once|include_once)\\s*[\\(]?['\"]([^\\._-]*?)(\\b{$pattern}\\b.*?)['\"][\\)]?;#is", $fileContents, $match)) {
                             if ('vendor/' === $match[2]) {
                                 continue;
                             }
                             $replaceCallback = array('pattern' => $pattern, 'replace' => $replace);
                             $fileContents = preg_replace_callback("#(include|require|require_once|include_once)\\s*[\\(]?['\"]([^\\._-]*?)(\\b{$pattern}\\b.*?)['\"][\\)]?;#is", function ($matches) use($replaceCallback) {
                                 if (!empty($matches[3])) {
                                     return preg_replace("#{$replaceCallback['pattern']}#is", "{$replaceCallback['replace']}", $matches[0]);
                                 } else {
                                     return $matches[0];
                                 }
                             }, $fileContents);
                             $this->backupFile($file);
                             $this->log("Updating {$file} with replacing vendor path");
                             sugar_file_put_contents($file, $fileContents);
                         }
                     }
                 }
             }
         }
     }
 }
 /**
  * @param string $fileNameToUpdate
  * @param array $app_list_strings
  * @param array $app_strings
  * @param int $keyCount - How many keys were changed
  * @param bool $fullArray - denotes if this is the full array or just additions
  */
 private function writeLanguageFile($fileNameToUpdate, $app_list_strings, $app_strings, $keyCount, $fullArray)
 {
     $this->logThis("-> Updating");
     $this->backupFile($fileNameToUpdate);
     $GLOBALS['log']->debug("fixLanguageFiles: BEGIN writeLanguageFile {$fileNameToUpdate}");
     if (!is_writable($fileNameToUpdate)) {
         $this->logThis("{$fileNameToUpdate} is not writable!!!!!!!", self::SEV_HIGH);
     }
     if ($keyCount > 0) {
         $this->logThis("-> {$keyCount} keys changed");
     }
     $flags = LOCK_EX;
     $moduleList = false;
     $moduleListSingular = false;
     $phpTag = "<?php";
     if (count($app_list_strings) > 0) {
         foreach ($app_list_strings as $key => $value) {
             if ($key == 'moduleList' && $moduleList == false) {
                 $the_string = "{$phpTag}\n";
                 foreach ($value as $mKey => $mValue) {
                     if (!empty($mValue)) {
                         $the_string .= "\$app_list_strings['moduleList']['{$mKey}'] = '{$mValue}';\n";
                     }
                 }
                 sugar_file_put_contents($fileNameToUpdate, $the_string, $flags);
                 $flags = FILE_APPEND | LOCK_EX;
                 $phpTag = "";
                 $moduleList = true;
             } elseif ($key == 'moduleListSingular' && $moduleListSingular == false) {
                 $the_string = "{$phpTag}\n";
                 foreach ($value as $mKey => $mValue) {
                     if (!empty($mValue)) {
                         $the_string .= "\$app_list_strings['moduleListSingular']['{$mKey}'] = '{$mValue}';\n";
                     }
                 }
                 sugar_file_put_contents($fileNameToUpdate, $the_string, $flags);
                 $flags = FILE_APPEND | LOCK_EX;
                 $phpTag = "";
                 $moduleListSingular = true;
             } else {
                 if ($fullArray) {
                     $the_string = "{$phpTag}\n\$app_list_strings['{$key}'] = " . var_export_helper($app_list_strings[$key]) . ";\n";
                 } else {
                     $the_string = "{$phpTag}\n";
                     foreach ($value as $mKey => $mValue) {
                         if (!empty($mValue)) {
                             $the_string .= "\$app_list_strings['moduleList']['{$mKey}'] = '{$mValue}';\n";
                         }
                     }
                 }
                 sugar_file_put_contents($fileNameToUpdate, $the_string, $flags);
                 $flags = FILE_APPEND | LOCK_EX;
                 $phpTag = "";
             }
         }
     } else {
         $flags = LOCK_EX;
     }
     if (count($app_strings) > 0) {
         $the_string = "{$phpTag}\n";
         foreach ($app_strings as $key => $value) {
             if ($value == NULL || $key == NULL) {
                 continue;
             }
             $the_string .= "\$app_strings['{$key}']='{$value}';\n";
         }
         sugar_file_put_contents($fileNameToUpdate, $the_string, $flags);
     }
     //Make sure the final file is loadable
     // If there is an error this REQUIRE will error out
     require $fileNameToUpdate;
     $GLOBALS['log']->debug("fixLanguageFiles: END writeLanguageFile");
 }
    protected function loadDefaultMetadata()
    {
        $defaultDefs = parent::loadDefaultMetadata();
        if (!empty($defaultDefs) && !empty($this->base_defsfile) && !empty($this->defsfile)) {
            // If we loaded template one, copy it to base file so we could load the parser
            // We only do this if the module is deployed though
            if ((file_exists($this->base_defsfile) || !file_exists($this->defsfile)) && $this->deployed) {
                $this->logUpgradeStatus("Copying template defs {$this->base_defsfile} to {$this->defsfile}");
                mkdir_recursive(dirname($this->defsfile));
                $client = $this->client == 'wireless' ? 'mobile' : $this->client;
                $viewname = pathinfo($this->defsfile, PATHINFO_FILENAME);
                $export = var_export($defaultDefs, true);
                $data = <<<END
<?php
/* Generated by SugarCRM Upgrader */
\$viewdefs['{$this->getNormalizedModuleName()}']['{$client}']['view']['{$viewname}'] = {$export};
END;
                sugar_file_put_contents($this->defsfile, $data);
            }
        }
        return $defaultDefs;
    }
 public function testCanLoadCustomEnglishLanguageAppStringsWhenCurrentLanguageDoesNotExist()
 {
     $GLOBALS['current_language'] = 'FR_fr';
     sugar_mkdir("modules/{$this->_moduleName}/Dashlets/TestModuleDashlet/", null, true);
     sugar_file_put_contents("modules/{$this->_moduleName}/Dashlets/TestModuleDashlet/TestModuleDashlet.en_us.lang.php", '<?php $dashletStrings["TestModuleDashlet"]["foo"] = "bar"; ?>');
     create_custom_directory("modules/{$this->_moduleName}/Dashlets/TestModuleDashlet/");
     sugar_file_put_contents("custom/modules/{$this->_moduleName}/Dashlets/TestModuleDashlet/TestModuleDashlet.en_us.lang.php", '<?php $dashletStrings["TestModuleDashlet"]["foo"] = "barbarbar"; ?>');
     $dashlet = new Dashlet(0);
     $dashlet->loadLanguage('TestModuleDashlet', "modules/{$this->_moduleName}/Dashlets/");
     $this->assertEquals("barbarbar", $dashlet->dashletStrings["foo"]);
 }
 /**
  * Shows a list of files that might need manual updating
  *
  * @param $searchString
  * @param $oldKey
  * @return bool
  */
 private function updateFiles($newKey, $oldKey)
 {
     $matches = array();
     if (empty($newKey) || in_array($oldKey, $this->customListNames)) {
         return false;
     }
     $searchString1 = "'" . $oldKey . "'";
     $searchString2 = '"' . $oldKey . '"';
     foreach ($this->customOtherFileList as $fileName) {
         $text = sugar_file_get_contents($fileName);
         if (strpos($text, $searchString1) !== FALSE || strpos($text, $searchString2) !== FALSE) {
             $oldText = array("=> '{$oldKey}'", "=> \"{$oldKey}\"", "=>'{$oldKey}'", "=>\"{$oldKey}\"", "= '{$oldKey}'", "= \"{$oldKey}\"", "='{$oldKey}'", "=\"{$oldKey}\"");
             $newText = array("=> '{$newKey}'", "=> \"{$newKey}\"", "=>'{$newKey}'", "=>\"{$newKey}\"", "= '{$newKey}'", "= \"{$newKey}\"", "='{$newKey}'", "=\"{$newKey}\"");
             $text = str_replace($oldText, $newText, $text);
             if (strpos($text, $searchString1) !== FALSE) {
                 $matches[$fileName] = true;
                 $this->customListNames[] = $oldKey;
             } else {
                 sugar_file_put_contents($fileName, $text, LOCK_EX);
             }
         }
     }
     if (!empty($matches)) {
         $this->logThis("------------------------------------------------------------", self::SEV_MEDIUM);
         $this->logThis("These files MAY need to be updated to reflect the new key (New '{$newKey}' vs. old '{$oldKey}')", self::SEV_MEDIUM);
         $this->logThis("-------------------------------------------------------------", self::SEV_MEDIUM);
         foreach ($matches as $fileName => $flag) {
             $this->logThis("{$fileName}", self::SEV_MEDIUM);
         }
         $this->logThis("-------------------------------------------------------------", self::SEV_MEDIUM);
     }
 }