Exemple #1
0
function write_logic_file($module_name, $contents)
{
    $file = "modules/" . $module_name . '/logic_hooks.php';
    $file = create_custom_directory($file);
    $fp = sugar_fopen($file, 'wb');
    fwrite($fp, $contents);
    fclose($fp);
    SugarAutoLoader::addToMap($file);
    //end function write_logic_file
}
 /**
  * adds current connector hash to cache
  * @param string $key
  * @param string $hash
  */
 protected function addToHash($key, $hash)
 {
     $hashes = array();
     $path = sugar_cached("api/metadata/connectorHashes.php");
     @(include $path);
     $hashes[$key] = $hash;
     write_array_to_file("hashes", $hashes, $path);
     SugarAutoLoader::addToMap($path);
 }
$name = '';
$description = '';
$is_uninstallable = true;
$id_name = '';
$dependencies = array();
$remove_tables = 'true';
$roles = array();
unzip($install_file, $unzip_dir);
if ($install_type == 'module' && $mode != 'Uninstall' && $mode != 'Disable') {
    //if LICENSE file not found, try LICENSE.txt
    if (!file_exists($license_file)) {
        $license_file = $unzip_dir . '/LICENSE.txt';
    }
    if (file_exists($license_file)) {
        // Add this to the autoloader so that it gets picked up when needed
        SugarAutoLoader::addToMap($license_file, true);
        $require_license = true;
    } else {
        $GLOBALS['log']->error("License File {$license_file} does not exist");
    }
}
//Scan the unzip dir for unsafe files
if ((defined('MODULE_INSTALLER_PACKAGE_SCAN') && MODULE_INSTALLER_PACKAGE_SCAN || !empty($GLOBALS['sugar_config']['moduleInstaller']['packageScan'])) && $install_type != 'patch') {
    require_once 'ModuleInstall/ModuleScanner.php';
    $ms = new ModuleScanner();
    $ms->scanPackage($unzip_dir);
    if ($ms->hasIssues()) {
        rmdir_recursive($unzip_dir);
        $ms->displayIssues();
        sugar_cleanup(true);
    }
 /**
  * Saves the company logo to the custom directory for the default theme, so all themes can use it
  *
  * @param string $path path to the image to set as the company logo image
  */
 function saveCompanyLogo($path)
 {
     $path = $this->checkTempImage($path);
     $logo = create_custom_directory(SugarThemeRegistry::current()->getDefaultImagePath() . '/company_logo.png');
     copy($path, $logo);
     SugarAutoLoader::addToMap($logo);
     sugar_cache_clear('company_logo_attributes');
     SugarThemeRegistry::clearAllCaches();
     SugarThemeRegistry::current()->clearImageCache('company_logo.png');
     MetaDataManager::refreshSectionCache(array(MetaDataManager::MM_LOGOURL));
 }
 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 {
         $moduleIndex = $useVariables ? '$module_name' : "'{$this->_moduleName}'";
         $out .= '$' . $viewVariable . "[{$moduleIndex}] = \n" . var_export_helper($defs);
     }
     $out .= ";\n";
     // Leaving off the closing PHP tag
     if (sugar_file_put_contents($filename, $out) === false) {
         $GLOBALS['log']->fatal(get_class($this) . ": could not write new viewdef file " . $filename);
     }
     // Add this file to the File Cache map
     SugarAutoLoader::addToMap($filename);
 }
 function handleSave($populate = true)
 {
     if (empty($this->_packageName)) {
         foreach (array(MB_CUSTOMMETADATALOCATION, MB_BASEMETADATALOCATION) as $value) {
             $file = $this->implementation->getFileName(MB_POPUPLIST, $this->_moduleName, $value);
             if (file_exists($file)) {
                 break;
             }
         }
         $writeFile = $this->implementation->getFileName(MB_POPUPLIST, $this->_moduleName);
         if (!file_exists($writeFile)) {
             mkdir_recursive(dirname($writeFile));
         }
     } else {
         $writeFile = $file = $this->implementation->getFileName(MB_POPUPLIST, $this->_moduleName, $this->_packageName);
     }
     $this->implementation->_history->append($file);
     if ($populate) {
         $this->_populateFromRequest();
     }
     $out = "<?php\n";
     //Load current module languages
     global $mod_strings, $current_language;
     $oldModStrings = $mod_strings;
     $GLOBALS['mod_strings'] = return_module_language($current_language, $this->_moduleName);
     require $file;
     if (!isset($popupMeta)) {
         sugar_die("unable to load Module Popup Definition");
     }
     if ($this->_view == MB_POPUPSEARCH) {
         foreach ($this->_viewdefs as $k => $v) {
             if (isset($this->_viewdefs[$k]) && isset($this->_viewdefs[$k]['default'])) {
                 unset($this->_viewdefs[$k]['default']);
             }
         }
         $this->_viewdefs = $this->convertSearchToListDefs($this->_viewdefs);
         $popupMeta['searchdefs'] = $this->_viewdefs;
         $this->addNewSearchDef($this->_viewdefs, $popupMeta);
     } else {
         $popupMeta['listviewdefs'] = array_change_key_case($this->_viewdefs, CASE_UPPER);
     }
     //provide a way for users to add to the reserve properties list via the 'addToReserve' element
     $totalReserveProps = self::$reserveProperties;
     if (!empty($popupMeta['addToReserve'])) {
         $totalReserveProps = array_merge(self::$reserveProperties, $popupMeta['addToReserve']);
     }
     $allProperties = array_merge($totalReserveProps, array('searchdefs', 'listviewdefs'));
     $out .= "\$popupMeta = array (\n";
     foreach ($allProperties as $p) {
         if (isset($popupMeta[$p])) {
             $out .= "    '{$p}' => " . var_export_helper($popupMeta[$p]) . ",\n";
         }
     }
     $out .= ");\n";
     file_put_contents($writeFile, $out);
     SugarAutoLoader::addToMap($writeFile);
     //return back mod strings
     $GLOBALS['mod_strings'] = $oldModStrings;
 }
function build_plugin_list()
{
    $plugin_list_dump = extract_plugin_list();
    $file = "workflow/plugins/plugin_list.php";
    $file = create_custom_directory($file);
    write_array_to_file('plugin_list', $plugin_list_dump, $file);
    SugarAutoLoader::addToMap($file);
}
function write_workflow(&$workflow_object)
{
    global $beanlist;
    $module = $workflow_object->base_module;
    $file = "modules/" . $module . '/workflow/workflow.php';
    $file = create_custom_directory($file);
    $dump = $workflow_object->get_trigger_contents();
    $fp = sugar_fopen($file, 'wb');
    fwrite($fp, "<?php\n");
    fwrite($fp, '
include_once("include/workflow/alert_utils.php");
include_once("include/workflow/action_utils.php");
include_once("include/workflow/time_utils.php");
include_once("include/workflow/trigger_utils.php");
//BEGIN WFLOW PLUGINS
include_once("include/workflow/custom_utils.php");
//END WFLOW PLUGINS
	class ' . $workflow_object->base_module . '_workflow {
	function process_wflow_triggers(& $focus){
		include("custom/modules/' . $module . '/workflow/triggers_array.php");
		include("custom/modules/' . $module . '/workflow/alerts_array.php");
		include("custom/modules/' . $module . '/workflow/actions_array.php");
		include("custom/modules/' . $module . '/workflow/plugins_array.php");
		' . $dump . '
	//end function process_wflow_triggers
	}

	//end class
	}
');
    fwrite($fp, "\n?>");
    fclose($fp);
    SugarAutoLoader::addToMap($file);
    //end function write_triggers
}
 /**
  * Change old labels to new ones in all $module subpanels
  * @param $module
  * @return bool
  */
 public function upgradeSubpanelModuleLabels($module)
 {
     $upgradeLabels = $this->upgradeLabels[$module];
     $upgradeDriver = $this->upgrader;
     $upgraded = false;
     // upgrade viewdefs
     $path = "custom/modules/{$module}/clients/base/views/subpanel-for-*/subpanel-for-*.php";
     foreach (glob($path) as $scanFile) {
         $viewdefs = array();
         include $scanFile;
         // Modification flag
         $changed = false;
         array_walk_recursive($viewdefs, function (&$value, $key) use(&$changed, $upgradeLabels, $upgradeDriver, $scanFile) {
             if ('label' == $key && isset($upgradeLabels[$value])) {
                 $upgradeDriver->log(sprintf('FixCustomLabelsForCoreModules: Fix label name from "%s" to "%s" in file "%s"', $value, $upgradeLabels[$value], $scanFile));
                 $value = $upgradeLabels[$value];
                 $changed = true;
             }
         });
         if ($changed) {
             $this->backupFile($scanFile);
             $upgraded = $upgraded || $changed;
             $keyNames = array();
             $viewdefsWrite = $viewdefs;
             // collect key names for array path "{module}/{platform}/{view_type}/{view}"
             for ($i = 0; $i < 4; $i++) {
                 if (1 != count($viewdefsWrite)) {
                     break;
                 }
                 $keyNames[] = key($viewdefsWrite);
                 $viewdefsWrite = $viewdefsWrite[key($viewdefsWrite)];
             }
             $out = "<?php\n// created: ' . date('Y-m-d H:i:s')\n";
             $out .= override_value_to_string_recursive($keyNames, 'viewdefs', $viewdefsWrite);
             if (sugar_file_put_contents_atomic($scanFile, $out) !== false) {
                 // record custom writes to file map
                 SugarAutoLoader::addToMap($scanFile);
             }
             unset($out);
             unset($viewdefsWrite);
         }
         unset($viewdefs);
     }
     // upgrade subpanel_layout
     $path = "custom/modules/{$module}/metadata/subpanels/*.php";
     foreach (glob($path) as $scanFile) {
         $subpanel_layout = array();
         include $scanFile;
         // Modification flag
         $changed = false;
         array_walk_recursive($subpanel_layout, function (&$value, $key) use(&$changed, $upgradeLabels, $upgradeDriver, $scanFile) {
             if ('vname' == $key && isset($upgradeLabels[$value])) {
                 $upgradeDriver->log(sprintf('FixCustomLabelsForCoreModules: Fix label name from "%s" to "%s" in file "%s"', $value, $upgradeLabels[$value], $scanFile));
                 $value = $upgradeLabels[$value];
                 $changed = true;
             }
         });
         if ($changed) {
             $upgraded = $upgraded || $changed;
             $this->backupFile($scanFile);
             write_array_to_file('subpanel_layout', $subpanel_layout, $scanFile, 'w');
         }
         unset($subpanel_layout);
     }
     return $upgraded;
 }
 function handleSave($populate = true)
 {
     if (empty($this->_packageName)) {
         foreach (array(MB_CUSTOMMETADATALOCATION, MB_BASEMETADATALOCATION) as $value) {
             $file = $this->implementation->getFileName(MB_DASHLET, $this->_moduleName, $value);
             if (file_exists($file)) {
                 break;
             }
         }
         $writeTodashletName = $dashletName = $this->implementation->getLanguage() . 'Dashlet';
         if (!file_exists($file)) {
             $file = "modules/{$this->_moduleName}/Dashlets/My{$this->_moduleName}Dashlet/My{$this->_moduleName}Dashlet.data.php";
             $dashletName = 'My' . $this->implementation->getLanguage() . 'Dashlet';
         }
         $writeFile = $this->implementation->getFileName(MB_DASHLET, $this->_moduleName);
         if (!file_exists($writeFile)) {
             mkdir_recursive(dirname($writeFile));
         }
     } else {
         $writeFile = $file = $this->implementation->getFileName(MB_DASHLET, $this->_moduleName, $this->_packageName);
         $writeTodashletName = $dashletName = $this->implementation->module->key_name . 'Dashlet';
     }
     $this->implementation->_history->append($file);
     if ($populate) {
         $this->_populateFromRequest();
     }
     $out = "<?php\n";
     require $file;
     if (!isset($dashletData[$dashletName])) {
         sugar_die("unable to load Module Dashlet Definition");
     }
     if ($fh = sugar_fopen($writeFile, 'w')) {
         if ($this->_view == MB_DASHLETSEARCH) {
             $dashletData[$dashletName]['searchFields'] = $this->ConvertSearchToDashletDefs($this->_viewdefs);
         } else {
             $dashletData[$dashletName]['columns'] = $this->_viewdefs;
         }
         $out .= "\$dashletData['{$writeTodashletName}']['searchFields'] = " . var_export_helper($dashletData[$dashletName]['searchFields']) . ";\n";
         $out .= "\$dashletData['{$writeTodashletName}']['columns'] = " . var_export_helper($dashletData[$dashletName]['columns']) . ";\n";
         fputs($fh, $out);
         fclose($fh);
         // Add this to the autoloader so that it gets picked up when needed
         SugarAutoLoader::addToMap($writeFile, true);
     }
 }
/**
 * sugar_touch
 * Attempts to set the access and modification times of the file named in the filename
 * parameter to the value given in time . Note that the access time is always modified,
 * regardless of the number of parameters.  If the file does not exist it will be created.
 * This method is basically a wrapper to the PHP touch method except that created files
 * may be set with the permissions specified in the configuration file (if set).
 *
 * @param $filename - The name of the file being touched.
 * @param $time - The touch time. If time  is not supplied, the current system time is used.
 * @param $atime - If present, the access time of the given filename is set to the value of atime
 * @return boolean - Returns TRUE on success or FALSE on failure.
 *
 */
function sugar_touch($filename, $time = null, $atime = null)
{
    if (!empty($GLOBALS['sugar_config']['default_permissions']['dir_mode'])) {
        $dirmode = $GLOBALS['sugar_config']['default_permissions']['dir_mode'];
    } else {
        $dirmode = null;
    }
    $result = sugar_mkdir(dirname($filename), $dirmode, true);
    if (!$result) {
        return $result;
    }
    if (!empty($atime) && !empty($time)) {
        $result = @touch($filename, $time, $atime);
    } else {
        if (!empty($time)) {
            $result = @touch($filename, $time);
        } else {
            $result = @touch($filename);
        }
    }
    if (!$result) {
        $GLOBALS['log']->error("File {$filename} cannot be touched");
        return $result;
    }
    if (!empty($GLOBALS['sugar_config']['default_permissions']['file_mode'])) {
        sugar_chmod($filename, $GLOBALS['sugar_config']['default_permissions']['file_mode']);
    }
    if (!empty($GLOBALS['sugar_config']['default_permissions']['user'])) {
        sugar_chown($filename);
    }
    if (!empty($GLOBALS['sugar_config']['default_permissions']['group'])) {
        sugar_chgrp($filename);
    }
    // Add this to the file loader cache
    if (!SugarAutoLoader::fileExists($filename)) {
        SugarAutoLoader::addToMap($filename);
    }
    return true;
}
Exemple #12
0
/**
 * Renames a file. If $new_file already exists, it will first unlink it and then rename it.
 * used in SugarLogger.php
 * @param string $old_filename
 * @param string $new_filename
 */
function sugar_rename($old_filename, $new_filename)
{
    if (empty($old_filename) || empty($new_filename)) {
        return false;
    }
    $success = false;
    if (SugarAutoLoader::fileExists($new_filename)) {
        SugarAutoLoader::unlink($new_filename);
        $success = rename($old_filename, $new_filename);
    } else {
        $success = rename($old_filename, $new_filename);
    }
    if ($success) {
        SugarAutoLoader::addToMap($new_filename);
    }
    return $success;
}
Exemple #13
0
    /**
     * Write out a file containing the set of alerts to be processed
     * @param module - the module to write the file for
     * @param contents - the contents of the file
     */
    function write_workflow_alerts_file($module, $contents)
    {
        global $beanlist;
        $file = "modules/" . $module . "/workflow/workflow_alerts.php";
        $file = create_custom_directory($file);
        $fp = sugar_fopen($file, 'wb');
        fwrite($fp, "<?php\n");
        fwrite($fp, '
include_once("include/workflow/alert_utils.php");
    class ' . $module . '_alerts {
    ' . $contents . '

    //end class
    }
');
        fwrite($fp, "\n?>");
        fclose($fp);
        SugarAutoLoader::addToMap($file);
        //end function write_alert_meta_file
    }