new_path = empty($new_path) || preg_match('/[\/]$/', $new_path) ? $new_path : $new_path . '/'; $this->original_path = empty($original_path) || preg_match('/[\/]$/', $original_path) ? $original_path : $original_path . '/'; $this->custom_path = empty($custom_path) || preg_match('/[\/]$/', $custom_path) ? $custom_path : $custom_path . '/'; $this->mergeMapping = array( 'editviewdefs.php'=> new EditViewMerge(), 'detailviewdefs.php'=>new DetailViewMerge(), 'listviewdefs.php'=>new ListViewMerge(), 'searchdefs.php'=>new SearchMerge(), 'quickcreatedefs.php'=>new QuickCreateMerge(), ); } function setLogFilePointer($fp){ $this->fp = $fp; } /** * This will run through all the modules that may need merging and determine if there is anything to merge * if $merge is set to true it will perform the merge * if $merge and $save are set to true it will perform the merge and save the results in the custom directory * * @param BOOLEAN $merge - do we wish to perform the merge if false it will just return a list of files that can be merged * @param BOOLEAN $save - do we wish to save the merged files to true - $merge must be true for this to apply - otherwise it will simulate merging so you can view the log files of the merge * @return ARRAY - an associative array of module names to files that were either merged or have the potential to be merged depeneding if $merge and $save are set to true */ function mergeAll($merge=true, $save=true){ $this->merged = array(); $searchDirectory = $this->custom_path; if(!preg_match('/[\/]modules$/si', $searchDirectory)) { $searchDirectory .= preg_match('/[\/]$/', $this->custom_path) ? 'modules' : '/modules'; } if(file_exists($searchDirectory)){ $dir = dir($searchDirectory); while($e = $dir->read()){ if(substr($e , 0, 1) != '.') { if(is_dir("{$searchDirectory}/{$e}/metadata")){ $this->merged[$e] = $this->mergeModule($e, $merge, $save ); } } } } return $this->merged; } /** * This will merge any files that need merging for a given module * if $merge is set to true it will perform the merge * if $merge and $save are set to true it will perform the merge and save the results in the custom directory * * @param STRING $module - the name of the module to merge files for * @param BOOLEAN $merge - do we wish to perform the merge if false it will just return a list of files that can be merged * @param BOOLEAN $save - do we wish to save the merged files to true - $merge must be true for this to apply - otherwise it will simulate merging so you can view the log files of the merge * @return ARRAY - an associative array of files that were either merged or have the potential to be merged depeneding if $merge and $save are set to true */ function mergeModule($module, $merge = true, $save=true){ $merged = array(); $path = $this->original_path . 'modules/' . $module . '/metadata/'; $custom_path = $this->custom_path . 'modules/' . $module . '/metadata/'; $new_path = $this->new_path . 'modules/' . $module . '/metadata/'; foreach($this->mergeMapping as $file=>&$object){ if(file_exists("{$custom_path}{$file}") && file_exists("{$new_path}{$file}")){ if($merge){ $merged[$file] = $this->mergeFile($module, $file, $save); }else{ $merged[$file] = true; } } } return $merged; } /** * This function will merge a single file for a module * * @param STRING $module - name of the module * @param STRING $file - name of the file * @param STRING $save - should the merged file be saved to the custom directory * @return BOOLEAN - success or failure of the merge */ function mergeFile($module, $file, $save=true){ $path = $this->original_path . 'modules/' . $module . '/metadata/'; $custom_path = $this->custom_path . 'modules/' . $module . '/metadata/'; $new_path = $this->new_path . 'modules/' . $module . '/metadata/'; if($this->fp) $this->mergeMapping[$file]->setLogFilePointer($this->fp); if(isset($this->mergeMapping[$file]) && file_exists("{$path}{$file}") && file_exists("{$custom_path}{$file}") && file_exists("{$new_path}{$file}")){ return $this->mergeMapping[$file]->merge($module, "{$path}{$file}", "{$new_path}{$file}", "{$custom_path}{$file}", $save); } return false; } /** * Return the custom modules path * * @return STRING directory where custom module files are located */ function getCustomPath() { return $this->custom_path; } /** * Return the new upgrade modules path * * @return STRING directory where new module files are located */ function getNewPath() { return $this->new_path; } /** * Return the original modules path * * @return STRING directory where new module files are located */ function getOriginalPath() { return $this->original_path; } } ?>