Ejemplo n.º 1
0
 public static function clearCache()
 {
     $file = sugar_cached('modules/unified_search_modules.php');
     if (SugarAutoLoader::fileExists($file)) {
         SugarAutoLoader::unlink($file);
     }
 }
 /**
  * Metadata fixes for the RLI Module
  *
  * - Removes the file that shows the RLI Module
  * - Removes the Studio File
  * - Hides the RLI module from the menu bar
  * - Removes the ACL Actions
  */
 protected function fixRevenueLineItemModule()
 {
     // hide the RLI module from the quick create, this needs to be done first, so it's properly removed
     $this->toggleRevenueLineItemQuickCreate(false);
     // cleanup on the current request
     $GLOBALS['modInvisList'][] = 'RevenueLineItems';
     if (isset($GLOBALS['moduleList']) && is_array($GLOBALS['moduleList'])) {
         foreach ($GLOBALS['moduleList'] as $key => $mod) {
             if ($mod === 'RevenueLineItems') {
                 unset($GLOBALS['moduleList'][$key]);
             }
         }
     }
     if (SugarAutoLoader::fileExists($this->appExtFolder . '/Include/' . $this->rliModuleExtFile)) {
         SugarAutoLoader::unlink($this->appExtFolder . '/Include/' . $this->rliModuleExtFile);
     }
     if (SugarAutoLoader::fileExists($this->rliStudioFile)) {
         SugarAutoLoader::unlink($this->rliStudioFile);
     }
     if (SugarAutoLoader::fileExists($this->rliModuleExtFolder . '/Vardefs/' . $this->rliModuleExtVardefFile)) {
         SugarAutoLoader::unlink($this->rliModuleExtFolder . '/Vardefs/' . $this->rliModuleExtVardefFile);
     }
     // hide the RLI module in workflows
     $affected_modules = $this->toggleRevenueLineItemsLinkInWorkFlows(false);
     // hide the mega menu tab
     $this->setRevenueLineItemModuleTab(false);
     // handle the parent type field
     $this->setRevenueLineItemInParentRelateDropDown(false);
     // disable the ACLs on RevenueLineItems
     ACLAction::removeActions('RevenueLineItems');
     // add the RLI module
     $affected_modules[] = 'RevenueLineItems';
     return $affected_modules;
 }
Ejemplo n.º 3
0
 /**
  * Saves the contents of the source files to the cache file or removes it
  * depending on the number of the source files
  *
  * @param array $sourceFiles Source file paths
  * @param string $cacheFile Cache file paths
  */
 protected function cacheExtensionFiles(array $sourceFiles, $cacheFile)
 {
     if (count($sourceFiles) > 0) {
         $sourceFiles = $this->sortExtensionFiles($sourceFiles);
         $contents = $this->getExtensionFileContents($sourceFiles);
         $dirName = dirname($cacheFile);
         if (!file_exists($dirName)) {
             mkdir_recursive($dirName, true);
         }
         SugarAutoLoader::put($cacheFile, $contents, true);
     } else {
         if (file_exists($cacheFile)) {
             SugarAutoLoader::unlink($cacheFile, true);
         }
     }
 }
Ejemplo n.º 4
0
 /**
  * Removes module cache files. This can clear a single cache file by type or
  * all cache files for a module. Can also clear a single platform type cache
  * for a module.
  *
  * @param array $modules The modules to clear the cache for. An empty array
  *                       clears caches for all modules
  * @param string $type   The cache file to clear. An empty string clears all
  *                       cache files for a module
  * @param array $platforms A list of platforms to clear the caches for. An
  *                         empty platform list assumes all platforms.
  */
 public static function clearModuleClientCache($modules = array(), $type = '', $platforms = array())
 {
     // Clean up the module list
     if (is_string($modules)) {
         // They just want one module
         $modules = array($modules);
     } elseif (count($modules) == 0) {
         // They want all of the modules, so get them if they are already set
         $modules = empty($GLOBALS['app_list_strings']['moduleList']) ? array() : array_keys($GLOBALS['app_list_strings']['moduleList']);
     }
     // Clean up the type
     if (empty($type)) {
         $type = '*';
     }
     // Clean up the platforms
     if (empty($platforms)) {
         $platforms = array('*');
     }
     // Handle it
     foreach ($modules as $module) {
         // Start at the client dir level
         $clientDirs = glob(sugar_cached('modules/' . $module . '/clients/'));
         foreach ($clientDirs as $clientDir) {
             foreach ($platforms as $platform) {
                 // Build up to the platform dir level
                 $platformDirs = glob($clientDir . $platform . '/');
                 foreach ($platformDirs as $platformDir) {
                     // Get all of the files in question
                     $cacheFiles = glob($platformDir . $type . '.php');
                     // Handle nuking the files
                     foreach ($cacheFiles as $cacheFile) {
                         SugarAutoLoader::unlink($cacheFile);
                     }
                 }
             }
         }
     }
 }
Ejemplo n.º 5
0
 function removeCustomLabels()
 {
     $out = "";
     $languageDir = "custom/modules/{$this->module}/language";
     if (is_dir($languageDir)) {
         $files = scandir($languageDir);
         foreach ($files as $langFile) {
             if (substr($langFile, 0, 1) == '.') {
                 continue;
             }
             $language = substr($langFile, 0, strlen($langFile) - 9);
             SugarAutoLoader::unlink($languageDir . "/" . $langFile, true);
             LanguageManager::clearLanguageCache($this->module, $language);
             $out .= "Removed language file {$langFile}<br/>";
         }
     }
     return $out;
 }
Ejemplo n.º 6
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');
 }
 public function deploy($defs)
 {
     // We are saving to the custom file
     $savefile = $this->getMetadataFilename(MB_CUSTOMMETADATALOCATION);
     // Simple validation and sanity checking
     if (!is_dir(dirname($savefile))) {
         if (!sugar_mkdir(dirname($savefile), null, true)) {
             throw new Exception("Cannot create directory for {$savefile}");
         }
     }
     // Handle history
     if ($this->loadedMetadataFile === MB_HISTORYMETADATALOCATION) {
         $types = array(MB_WORKINGMETADATALOCATION, MB_CUSTOMMETADATALOCATION, MB_BASEMETADATALOCATION);
         foreach ($types as $type) {
             $file = $this->getMetadataFilename($type);
             if (file_exists($file)) {
                 $this->_history->append($file);
                 break;
             }
         }
     } else {
         $this->_history->append($this->loadedMetadataFile);
     }
     $this->_viewdefs = $defs;
     // Now save the actual data
     write_array_to_file("viewdefs['{$this->_moduleName}']['{$this->_viewClient}']['filter']['default']", $this->_viewdefs, $savefile);
     // Delete the working file if exists as we do in DeployedMetaDataImplementation
     $workingFilename = $this->getMetadataFilename(MB_WORKINGMETADATALOCATION);
     if (file_exists($workingFilename)) {
         SugarAutoLoader::unlink($workingFilename);
     }
     // clear the cache for this module
     MetaDataManager::refreshModulesCache(array($this->_moduleName));
 }
Ejemplo n.º 8
0
    protected function toggleRevenueLineItemsLinkInWorkFlows($show = false)
    {
        // make sure all the links are visible in workflows
        /* @var $rli_bean = RevenueLineItem */
        $rli_bean = BeanFactory::getBean('RevenueLineItems');
        $rli_links = $rli_bean->get_linked_fields();
        $rnr_modules = array();
        foreach ($rli_links as $name => $link) {
            if ($rli_bean->load_relationship($name) && $rli_bean->{$name} instanceof Link2) {
                $bean = BeanFactory::getBean($rli_bean->{$name}->getRelatedModuleName());
                $rel_name = $rli_bean->{$name}->getRelatedModuleLinkName();
                // if for some reason we didn't find a rli_name on the other side of the link
                // we should just ignore it
                if (empty($rel_name)) {
                    continue;
                }
                $file = 'rli_link_workflow.php';
                $folder = "custom/Extension/modules/{$bean->module_dir}/Ext";
                SugarAutoLoader::ensureDir($folder . '/Vardefs');
                if ($show === true) {
                    $file_contents = <<<EOL
<?php
\$dictionary['{$bean->object_name}']['fields']['{$rel_name}']['workflow'] = true;
EOL;
                    sugar_file_put_contents($folder . '/Vardefs/' . $file, $file_contents);
                } else {
                    if (SugarAutoLoader::fileExists($folder . '/Vardefs/' . $file)) {
                        // since we don't what to show it, just remove the file as it defaults
                        // to false out of the box.
                        SugarAutoLoader::unlink($folder . '/Vardefs/' . $file);
                    }
                }
                $rnr_modules[] = $bean->module_name;
            }
        }
        return $rnr_modules;
    }
Ejemplo n.º 9
0
 /**
  * Unlink file
  *
  * @param $file
  */
 protected function unlink($file)
 {
     if ($this->fileExists($file)) {
         SugarAutoLoader::unlink($file);
     }
 }
Ejemplo n.º 10
0
 /**
  * Find links with wrong relationship.
  * @param DefinitionObject $fieldDefs
  * @param SugarBean $seed
  * @return array Wrong relationships.
  */
 protected function checkFieldsRelationships($fieldDefs, $seed)
 {
     $wrongRelations = array();
     foreach ($fieldDefs as $fieldnm => $field) {
         // Check for bad links
         if ($field['type'] == 'link') {
             $seed->load_relationship($field['name']);
             $wRel = false;
             if (empty($seed->{$field}['name'])) {
                 $wRel = true;
             } else {
                 if ($this->checkRelationshipDef($field['name'], $seed)) {
                     // Need to delete cache of TableDictionary to avoid inclusion of deleted files.
                     if (file_exists('custom/application/Ext/TableDictionary/tabledictionary.ext.php')) {
                         SugarAutoLoader::unlink('custom/application/Ext/TableDictionary/tabledictionary.ext.php');
                     }
                     SugarRelationshipFactory::deleteCache();
                     SugarRelationshipFactory::rebuildCache();
                     unset($seed->{$field}['name']);
                     $seed->load_relationship($field['name']);
                 }
                 $relModule = $seed->{$field}['name']->getRelatedModuleName();
                 $relBean = $this->getBean($relModule);
                 if (empty($relBean)) {
                     $wRel = true;
                 }
             }
             if ($wRel) {
                 if (!empty($field['relationship'])) {
                     $wrongRelations[] = $field['relationship'];
                 }
                 $fieldDefs->setWrongDef($fieldnm);
             }
         }
     }
     return $wrongRelations;
 }
 /**
  * Searches for and removes any older layout override extensions that reference this subpanel
  * @param $layoutPath path to the layout extension folder for the current module
  */
 protected function removeOldOverideExtension($layoutPath, $client = 'base')
 {
     $files = glob("{$layoutPath}/_override*.php");
     foreach ($files as $override) {
         $viewdefs = array();
         @(include $override);
         if (!empty($viewdefs[$this->loadedModule][$client]['layout']['subpanels']['components'][0]['override_subpanel_list_view']['link']) && $viewdefs[$this->loadedModule][$client]['layout']['subpanels']['components'][0]['override_subpanel_list_view']['link'] == $this->linkName) {
             SugarAutoLoader::unlink($override);
         }
     }
 }
Ejemplo n.º 12
0
 public function undoRestore()
 {
     if (file_exists($this->_previewFilename)) {
         SugarAutoLoader::unlink($this->_previewFilename);
     }
 }
Ejemplo n.º 13
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;
}
 /**
  * Resets user specific metadata to default
  */
 public function resetToDefault()
 {
     if (count($this->params) > 0) {
         $fileName = $this->getFileNameNoDefault($this->_view, $this->_moduleName);
         if (file_exists($fileName)) {
             $this->saveHistory();
             SugarAutoLoader::unlink($fileName, true);
             MetaDataFiles::clearModuleClientCache($this->_moduleName, 'view');
             // Clear out the cache just for the platform we are on
             $client = empty($this->client) ? 'base' : $this->client;
             MetaDataManager::refreshModulesCache(array($this->_moduleName), array($client), $this->params);
         }
     }
 }