[ Index ] |
|
Code source de SugarCRM 5.0.0beta1 |
1 <?php 2 if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point'); 3 /********************************************************************************* 4 * SugarCRM is a customer relationship management program developed by 5 * SugarCRM, Inc. Copyright (C) 2004 - 2007 SugarCRM Inc. 6 * 7 * This program is free software; you can redistribute it and/or modify it under 8 * the terms of the GNU General Public License version 3 as published by the 9 * Free Software Foundation. 10 * 11 * This program is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 13 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 14 * details. 15 * 16 * You should have received a copy of the GNU General Public License along with 17 * this program; if not, see http://www.gnu.org/licenses or write to the Free 18 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 19 * 02110-1301 USA. 20 * 21 * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road, 22 * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com. 23 * 24 * The interactive user interfaces in modified source and object code versions 25 * of this program must display Appropriate Legal Notices, as required under 26 * Section 5 of the GNU General Public License version 3. 27 * 28 * In accordance with Section 7(b) of the GNU General Public License version 3, 29 * these Appropriate Legal Notices must retain the display of the "Powered by 30 * SugarCRM" logo. If the display of the logo is not reasonably feasible for 31 * technical reasons, the Appropriate Legal Notices must display the words 32 * "Powered by SugarCRM". 33 ********************************************************************************/ 34 require_once ('include/dir_inc.php'); 35 require_once ('include/utils/file_utils.php'); 36 require_once ('include/utils/progress_bar_utils.php'); 37 include_once ('include/database/DBManagerFactory.php'); 38 require_once ('modules/Relationships/Relationship.php'); 39 define('DISABLED_PATH', 'Disabled'); 40 41 class ModuleInstaller{ 42 var $modules = array(); 43 var $silent = false; 44 var $base_dir = ''; 45 function ModuleInstaller(){ 46 $this->modules = get_module_dir_list(); 47 $this->db = & DBManagerFactory::getInstance(); 48 49 50 } 51 function install($base_dir, $is_upgrade = false, $previous_version = ''){ 52 global $app_strings; 53 $this->base_dir = $base_dir; 54 $total_steps = 5; //minimum number of steps with no tasks 55 $current_step = 0; 56 $tasks = array( 57 'pre_execute', 58 'install_mkdirs', 59 'install_copy', 60 'install_images', 61 'install_menus', 62 'install_userpage', 63 'install_dashlets', 64 'install_administration', 65 'install_vardefs', 66 'install_layoutdefs', 67 'install_relationships', 68 'install_languages', 69 'post_execute', 70 ); 71 $total_steps += count($tasks); 72 if(file_exists($this->base_dir . '/manifest.php')){ 73 if(!$this->silent){ 74 $current_step++; 75 display_progress_bar('install', $current_step, $total_steps); 76 echo '<div id ="displayLoglink" ><a href="#" onclick="toggleDisplay(\'displayLog\')">'.$app_strings['LBL_DISPLAY_LOG'].'</a> </div><div id="displayLog" style="display:none">'; 77 } 78 79 require_once($this->base_dir . '/manifest.php'); 80 if($is_upgrade && !empty($previous_version)){ 81 //check if the upgrade path exists 82 if(!empty($upgrade_manifest)){ 83 if(!empty($upgrade_manifest['upgrade_paths'])){ 84 if(!empty($upgrade_manifest['upgrade_paths'][$previous_version])){ 85 $installdefs = $upgrade_manifest['upgrade_paths'][$previous_version]; 86 }else{ 87 $errors[] = 'No Upgrade Path Found in manifest.'; 88 $this->abort($errors); 89 }//fi 90 }//fi 91 }//fi 92 }//fi 93 $this->id_name = $installdefs['id']; 94 $this->installdefs = $installdefs; 95 $installed_modules = array(); 96 if(isset($installdefs['beans'])){ 97 $str = "<?php \n //WARNING: The contents of this file are auto-generated\n"; 98 foreach($installdefs['beans'] as $bean){ 99 if(!empty($bean['module']) && !empty($bean['class']) && !empty($bean['path'])){ 100 $module = $bean['module']; 101 $class = $bean['class']; 102 $path = $bean['path']; 103 104 $str .= "\$beanList['$module'] = '$class';\n"; 105 $str .= "\$beanFiles['$class'] = '$path';\n"; 106 if($bean['tab']){ 107 $str .= "\$moduleList[] = '$module';\n"; 108 $this->install_user_prefs($module, empty($bean['hide_by_default'])); 109 110 }else{ 111 $str .= "\$modInvisList[] = '$module';\n"; 112 } 113 $installed_modules[] = $module; 114 }else{ 115 $errors[] = 'Bean array not well defined.'; 116 $this->abort($errors); 117 } 118 } 119 $str.= "\n?>"; 120 if(!file_exists("custom/Extension/application/Ext/Include")){ 121 mkdir_recursive("custom/Extension/application/Ext/Include", true); 122 } 123 $out = fopen("custom/Extension/application/Ext/Include/$this->id_name.php", 'w'); 124 fwrite($out,$str); 125 fclose($out); 126 $this->merge_files('Ext/Include', 'modules.ext.php', '', true); 127 } 128 if(!$this->silent){ 129 $current_step++; 130 update_progress_bar('install', $current_step, $total_steps); 131 } 132 133 foreach($tasks as $task){ 134 $this->$task(); 135 if(!$this->silent){ 136 $current_step++; 137 update_progress_bar('install', $current_step, $total_steps); 138 } 139 } 140 $this->install_beans($installed_modules); 141 if(!$this->silent){ 142 $current_step++; 143 update_progress_bar('install', $total_steps, $total_steps); 144 } 145 if(isset($installdefs['custom_fields'])){ 146 $this->log('Installing Custom Fields...'); 147 $this->install_custom_fields($installdefs['custom_fields']); 148 } 149 if(!$this->silent){ 150 $current_step++; 151 update_progress_bar('install', $current_step, $total_steps); 152 echo '</div>'; 153 } 154 $this->rebuild_relationships(); 155 if(!$this->silent){ 156 $current_step++; 157 update_progress_bar('install', $current_step, $total_steps); 158 echo '</div>'; 159 } 160 161 $this->log('Complete'); 162 163 }else{ 164 die("No \$installdefs Defined In $this->base_dir/manifest.php"); 165 } 166 167 } 168 169 function install_user_prefs($module, $hide_from_user=false){ 170 require_once ('include/utils/user_utils.php'); 171 updateAllUserPrefs('display_tabs', $module, '', true, !$hide_from_user); 172 updateAllUserPrefs('hide_tabs', $module, '', true, $hide_from_user); 173 updateAllUserPrefs('remove_tabs', $module, '', true, $hide_from_user); 174 } 175 function uninstall_user_prefs($module){ 176 require_once ('include/utils/user_utils.php'); 177 updateAllUserPrefs('display_tabs', $module, '', true, true); 178 updateAllUserPrefs('hide_tabs', $module, '', true, true); 179 updateAllUserPrefs('remove_tabs', $module, '', true, true); 180 } 181 function install_mkdirs(){ 182 if(isset($this->installdefs['mkdir'])){ 183 foreach($this->installdefs['mkdir'] as $mkdir){ 184 $mkdir['path'] = str_replace('<basepath>', $this->base_dir, $mkdir['path']); 185 if(!mkdir_recursive($mkdir['path'], true)){ 186 die('Failed to make directory ' . $mkdir['path']); 187 } 188 } 189 } 190 } 191 192 function pre_execute(){ 193 require_once($this->base_dir . '/manifest.php'); 194 if(isset($this->installdefs['pre_execute']) && is_array($this->installdefs['pre_execute'])){ 195 foreach($this->installdefs['pre_execute'] as $includefile){ 196 require_once(str_replace('<basepath>', $this->base_dir, $includefile)); 197 } 198 } 199 } 200 201 function post_execute(){ 202 require_once($this->base_dir . '/manifest.php'); 203 if(isset($this->installdefs['post_execute']) && is_array($this->installdefs['post_execute'])){ 204 foreach($this->installdefs['post_execute'] as $includefile){ 205 require_once(str_replace('<basepath>', $this->base_dir, $includefile)); 206 } 207 } 208 } 209 210 function pre_uninstall(){ 211 require_once($this->base_dir . '/manifest.php'); 212 if(isset($this->installdefs['pre_uninstall']) && is_array($this->installdefs['pre_uninstall'])){ 213 foreach($this->installdefs['pre_uninstall'] as $includefile){ 214 require_once(str_replace('<basepath>', $this->base_dir, $includefile)); 215 } 216 } 217 } 218 219 function post_uninstall(){ 220 require_once($this->base_dir . '/manifest.php'); 221 if(isset($this->installdefs['post_uninstall']) && is_array($this->installdefs['post_uninstall'])){ 222 foreach($this->installdefs['post_uninstall'] as $includefile){ 223 require_once(str_replace('<basepath>', $this->base_dir, $includefile)); 224 } 225 } 226 } 227 228 function uninstall_mkdirs(){ 229 if(isset($this->installdefs['mkdir'])){ 230 foreach($this->installdefs['mkdir'] as $mkdir){ 231 $mkdir['path'] = str_replace('<basepath>', $this->base_dir, $mkdir['path']); 232 rmdir_recursive($mkdir['path']); 233 } 234 } 235 } 236 /* 237 * Copies both directories and files from a loaction to a location 238 */ 239 function install_copy(){ 240 if(isset($this->installdefs['copy'])){ 241 /* BEGIN - RESTORE POINT - by MR. MILK August 31, 2005 02:22:11 PM */ 242 $backup_path = clean_path( remove_file_extension(urldecode($_REQUEST['install_file']))."-restore" ); 243 /* END - RESTORE POINT - by MR. MILK August 31, 2005 02:22:18 PM */ 244 foreach($this->installdefs['copy'] as $cp){ 245 $GLOBALS['log']->debug("Copying ..." . $cp['from']. " to " .$cp['to'] ); 246 /* BEGIN - RESTORE POINT - by MR. MILK August 31, 2005 02:22:11 PM */ 247 //$this->copy_path($cp['from'], $cp['to']); 248 $this->copy_path($cp['from'], $cp['to'], $backup_path); 249 /* END - RESTORE POINT - by MR. MILK August 31, 2005 02:22:18 PM */ 250 } 251 //here we should get the module list again as we could have copied something to the modules dir 252 $this->modules = get_module_dir_list(); 253 } 254 } 255 function uninstall_copy(){ 256 if(!empty($this->installdefs['copy'])){ 257 foreach($this->installdefs['copy'] as $cp){ 258 $cp['to'] = clean_path(str_replace('<basepath>', $this->base_dir, $cp['to'])); 259 $GLOBALS['log']->debug('Unlink ' . $cp['to']); 260 /* BEGIN - RESTORE POINT - by MR. MILK August 31, 2005 02:22:11 PM */ 261 //rmdir_recursive($cp['to']); 262 $backup_path = clean_path( remove_file_extension(urldecode($_REQUEST['install_file']))."-restore/".$cp['to'] ); 263 $this->copy_path($backup_path, $cp['to'], $backup_path, true); 264 /* END - RESTORE POINT - by MR. MILK August 31, 2005 02:22:18 PM */ 265 } 266 $backup_path = clean_path( remove_file_extension(urldecode($_REQUEST['install_file']))."-restore"); 267 if(file_exists($backup_path)) 268 rmdir_recursive($backup_path); 269 } 270 } 271 272 273 function install_dashlets(){ 274 if(isset($this->installdefs['dashlets'])){ 275 foreach($this->installdefs['dashlets'] as $cp){ 276 $this->log("Installing Dashlet " . $cp['name']); 277 $cp['from'] = str_replace('<basepath>', $this->base_dir, $cp['from']); 278 $path = 'custom/modules/Home/Dashlets/' . $cp['name'] . '/'; 279 $GLOBALS['log']->debug("Installing Dashlet " . $cp['name'] . "..." . $cp['from'] ); 280 if(!file_exists($path)){ 281 mkdir_recursive($path, true); 282 } 283 copy_recursive($cp['from'] , $path); 284 } 285 include ('modules/Administration/RebuildDashlets.php'); 286 287 } 288 } 289 290 function uninstall_dashlets(){ 291 if(isset($this->installdefs['dashlets'])){ 292 foreach($this->installdefs['dashlets'] as $cp){ 293 $this->log("Uninstalling Dashlet " . $cp['name']); 294 $path = 'custom/modules/Home/Dashlets/' . $cp['name']; 295 $GLOBALS['log']->debug('Unlink ' .$path); 296 rmdir_recursive($path); 297 } 298 include ('modules/Administration/RebuildDashlets.php'); 299 } 300 } 301 302 303 function install_images(){ 304 if(isset($this->installdefs['image_dir'])){ 305 $this->log("Installing Images" ); 306 $this->copy_path($this->installdefs['image_dir'] , 'themes'); 307 308 } 309 } 310 311 function install_menus(){ 312 if(isset($this->installdefs['menu'])){ 313 $this->log('Installing menus'); 314 foreach($this->installdefs['menu'] as $menu){ 315 $menu['from'] = str_replace('<basepath>', $this->base_dir, $menu['from']); 316 $GLOBALS['log']->debug("Installing Menu ..." . $menu['from']. " for " .$menu['to_module'] ); 317 $path = 'custom/Extension/modules/' . $menu['to_module']. '/Ext/Menus'; 318 if($menu['to_module'] == 'application'){ 319 $path ='custom/Extension/' . $menu['to_module']. '/Ext/Menus'; 320 } 321 if(!file_exists($path)){ 322 mkdir_recursive($path, true); 323 324 } 325 copy_recursive($menu['from'] , $path . '/'. $this->id_name . '.php'); 326 } 327 $this->rebuild_menus(); 328 } 329 330 } 331 332 function uninstall_menus(){ 333 if(isset($this->installdefs['menu'])){ 334 $this->log('Uninstalling menus'); 335 foreach($this->installdefs['menu'] as $menu){ 336 $menu['from'] = str_replace('<basepath>', $this->base_dir, $menu['from']); 337 $GLOBALS['log']->debug("Uninstalling Menu ..." . $menu['from']. " for " .$menu['to_module'] ); 338 $path = 'custom/Extension/modules/' . $menu['to_module']. '/Ext/Menus'; 339 if($menu['to_module'] == 'application'){ 340 $path ='custom/Extension/' . $menu['to_module']. '/Ext/Menus'; 341 } 342 rmdir_recursive( $path . '/'. $this->id_name . '.php'); 343 344 } 345 $this->rebuild_menus(); 346 } 347 } 348 349 function install_administration(){ 350 if(isset($this->installdefs['administration'])){ 351 $this->log("Installing Administration Section "); 352 foreach($this->installdefs['administration'] as $administration){ 353 $administration['from'] = str_replace('<basepath>', $this->base_dir, $administration['from']); 354 $GLOBALS['log']->debug("Installing Administration Section ..." . $administration['from'] ); 355 $path = 'custom/Extension/modules/Administration/Ext/Administration'; 356 if(!file_exists($path)){ 357 mkdir_recursive($path, true); 358 359 } 360 copy_recursive($administration['from'] , $path . '/'. $this->id_name . '.php'); 361 } 362 $this->rebuild_administration(); 363 } 364 365 } 366 function uninstall_administration(){ 367 if(isset($this->installdefs['administration'])){ 368 $this->log("Uninstalling Administration Section "); 369 foreach($this->installdefs['administration'] as $administration){ 370 $administration['from'] = str_replace('<basepath>', $this->base_dir, $administration['from']); 371 $GLOBALS['log']->debug("Uninstalling Administration Section ..." . $administration['from'] ); 372 $path = 'custom/Extension/modules/Administration/Ext/Administration'; 373 rmdir_recursive( $path . '/'. $this->id_name . '.php'); 374 } 375 $this->rebuild_administration(); 376 } 377 } 378 379 function install_userpage(){ 380 if(isset($this->installdefs['user_page'])){ 381 $this->log("Installing User Page Section "); 382 foreach($this->installdefs['user_page'] as $userpage){ 383 $userpage['from'] = str_replace('<basepath>', $this->base_dir, $userpage['from']); 384 $GLOBALS['log']->debug("Installing User Page Section ..." . $userpage['from'] ); 385 $path = 'custom/Extension/modules/Users/Ext/UserPage'; 386 if(!file_exists($path)){ 387 mkdir_recursive($path, true); 388 389 } 390 copy_recursive($userpage['from'] , $path . '/'. $this->id_name . '.php'); 391 } 392 $this->rebuild_userpage(); 393 } 394 395 } 396 function uninstall_userpage(){ 397 if(isset($this->installdefs['user_page'])){ 398 $this->log("Uninstalling User Page Section" ); 399 foreach($this->installdefs['user_page'] as $userpage){ 400 $userpage['from'] = str_replace('<basepath>', $this->base_dir, $userpage['from']); 401 $GLOBALS['log']->debug("Uninstalling User Page Section ..." . $userpage['from'] ); 402 $path = 'custom/Extension/modules/Users/Ext/UserPage'; 403 rmdir_recursive( $path . '/'. $this->id_name . '.php'); 404 } 405 $this->rebuild_userpage(); 406 } 407 } 408 409 /* 410 * handles the installation of vardefs 411 * 412 */ 413 function install_vardefs(){ 414 if(isset($this->installdefs['vardefs'])){ 415 $this->log("Installing Variable Definitions" ); 416 foreach($this->installdefs['vardefs'] as $vardefs){ 417 $vardefs['from'] = str_replace('<basepath>', $this->base_dir, $vardefs['from']); 418 $this->install_vardef($vardefs['from'], $vardefs['to_module'], $this->id_name); 419 } 420 $this->rebuild_vardefs(); 421 } 422 } 423 function uninstall_vardefs(){ 424 if(isset($this->installdefs['vardefs'])){ 425 $this->log("Uninstalling Variable Definitions" ); 426 foreach($this->installdefs['vardefs'] as $vardefs){ 427 $vardefs['from'] = str_replace('<basepath>', $this->base_dir, $vardefs['from']); 428 $GLOBALS['log']->debug("Uninstalling Vardefs ..." . $vardefs['from'] . " for " .$vardefs['to_module']); 429 $path = 'custom/Extension/modules/' . $vardefs['to_module']. '/Ext/Vardefs'; 430 if($vardefs['to_module'] == 'application'){ 431 $path ='custom/Extension/' . $vardefs['to_module']. '/Ext/Vardefs'; 432 } 433 434 rmdir_recursive( $path . '/'. $this->id_name . '.php'); 435 } 436 $this->rebuild_vardefs(); 437 } 438 } 439 function install_vardef($from, $to_module){ 440 $GLOBALS['log']->debug("Installing Vardefs ..." . $from . " for " .$to_module); 441 $path = 'custom/Extension/modules/' . $to_module. '/Ext/Vardefs'; 442 if($to_module == 'application'){ 443 $path ='custom/Extension/' . $to_module. '/Ext/Vardefs'; 444 } 445 if(!file_exists($path)){ 446 mkdir_recursive($path, true); 447 } 448 copy_recursive($from , $path.'/'. $this->id_name . '.php'); 449 } 450 function install_layoutdefs(){ 451 if(isset($this->installdefs['layoutdefs'])){ 452 $this->log("Installing Subpanel Layouts" ); 453 foreach($this->installdefs['layoutdefs'] as $layoutdefs){ 454 $layoutdefs['from'] = str_replace('<basepath>', $this->base_dir, $layoutdefs['from']); 455 $this->install_layoutdef($layoutdefs['from'], $layoutdefs['to_module'], $this->id_name); 456 } 457 $this->rebuild_layoutdefs(); 458 } 459 } 460 function uninstall_layoutdefs(){ 461 if(isset($this->installdefs['layoutdefs'])){ 462 $this->log("Uninstalling Subpanel Layouts" ); 463 foreach($this->installdefs['layoutdefs'] as $layoutdefs){ 464 $layoutdefs['from'] = str_replace('<basepath>', $this->base_dir, $layoutdefs['from']); 465 $GLOBALS['log']->debug("Uninstalling Layoutdefs ..." . $layoutdefs['from'] . " for " .$layoutdefs['to_module']); 466 $path = 'custom/Extension/modules/' . $layoutdefs['to_module']. '/Ext/Layoutdefs'; 467 if($layoutdefs['to_module'] == 'application'){ 468 $path ='custom/Extension/' . $layoutdefs['to_module']. '/Ext/Layoutdefs'; 469 } 470 471 rmdir_recursive( $path . '/'. $this->id_name . '.php'); 472 } 473 $this->rebuild_layoutdefs(); 474 } 475 } 476 function install_layoutdef($from, $to_module){ 477 $GLOBALS['log']->debug("Installing Layout Defs ..." . $from . " for " .$to_module); 478 $path = 'custom/Extension/modules/' . $to_module. '/Ext/Layoutdefs'; 479 if($to_module == 'application'){ 480 $path ='custom/Extension/' . $to_module. '/Ext/Layoutdefs'; 481 } 482 if(!file_exists($path)){ 483 mkdir_recursive($path, true); 484 } 485 copy_recursive($from , $path.'/'. $this->id_name . '.php'); 486 } 487 488 function install_languages(){ 489 $languages = array(); 490 if(isset($this->installdefs['language'])){ 491 $this->log("Installing Language Packs" ); 492 foreach($this->installdefs['language'] as $packs){ 493 $languages[$packs['language']] = $packs['language']; 494 $packs['from'] = str_replace('<basepath>', $this->base_dir, $packs['from']); 495 $GLOBALS['log']->debug("Installing Language Pack ..." . $packs['from'] . " for " .$packs['to_module']); 496 $path = 'custom/Extension/modules/' . $packs['to_module']. '/Ext/Language'; 497 if($packs['to_module'] == 'application'){ 498 $path ='custom/Extension/' . $packs['to_module']. '/Ext/Language'; 499 } 500 501 if(!file_exists($path)){ 502 mkdir_recursive($path, true); 503 504 } 505 copy_recursive($packs['from'] , $path.'/'.$packs['language'].'.'. $this->id_name . '.php'); 506 } 507 $this->rebuild_languages($languages); 508 509 } 510 } 511 512 function uninstall_languages(){ 513 $languages = array(); 514 if(isset($this->installdefs['language'])){ 515 $this->log("Uninstalling Language Packs" ); 516 foreach($this->installdefs['language'] as $packs){ 517 $languages[] = $packs['language']; 518 $packs['from'] = str_replace('<basepath>', $this->base_dir, $packs['from']); 519 $GLOBALS['log']->debug("Uninstalling Language Pack ..." . $packs['from'] . " for " .$packs['to_module']); 520 $path = 'custom/Extension/modules/' . $packs['to_module']. '/Ext/Language'; 521 if($packs['to_module'] == 'application'){ 522 $path ='custom/Extension/' . $packs['to_module']. '/Ext/Language'; 523 } 524 525 rmdir_recursive( $path.'/'.$packs['language'].'.'. $this->id_name . '.php'); 526 527 } 528 $this->rebuild_languages($languages); 529 530 } 531 } 532 533 /* BEGIN - RESTORE POINT - by MR. MILK August 31, 2005 02:22:18 PM */ 534 function copy_path($from, $to, $backup_path='', $uninstall=false){ 535 //function copy_path($from, $to){ 536 /* END - RESTORE POINT - by MR. MILK August 31, 2005 02:22:18 PM */ 537 $to = str_replace('<basepath>', $this->base_dir, $to); 538 539 if(!$uninstall) { 540 $from = str_replace('<basepath>', $this->base_dir, $from); 541 $GLOBALS['log']->debug('Copy ' . $from); 542 } 543 else { 544 $from = str_replace('<basepath>', $backup_path, $from); 545 //$GLOBALS['log']->debug('Restore ' . $from); 546 } 547 $from = clean_path($from); 548 $to = clean_path($to); 549 550 $dir = dirname($to); 551 if(!file_exists($dir)) 552 mkdir_recursive($dir, true); 553 /* BEGIN - RESTORE POINT - by MR. MILK August 31, 2005 02:22:18 PM */ 554 if(empty($backup_path)) { 555 /* END - RESTORE POINT - by MR. MILK August 31, 2005 02:22:18 PM */ 556 if(!copy_recursive($from, $to)){ 557 die('Failed to copy ' . $from. ' ' . $to); 558 } 559 /* BEGIN - RESTORE POINT - by MR. MILK August 31, 2005 02:22:18 PM */ 560 } 561 elseif(!$this->copy_recursive_with_backup($from, $to, $backup_path, $uninstall)){ 562 die('Failed to copy ' . $from. ' ' . $to); 563 } 564 /* END - RESTORE POINT - by MR. MILK August 31, 2005 02:22:18 PM */ 565 } 566 567 function install_custom_fields($fields){ 568 global $beanList, $beanFiles; 569 include ('include/modules.php'); 570 foreach($fields as $field){ 571 $installed = false; 572 if(isset($beanList[ $field['module']])){ 573 $class = $beanList[ $field['module']]; 574 if(!isset($field['ext4']))$field['ext4'] = ''; 575 if(!isset($field['mass_update']))$field['mass_update'] = 0; 576 if(!isset($field['duplicate_merge']))$field['duplicate_merge'] = 0; 577 if(!isset($field['help']))$field['help'] = ''; 578 579 if(file_exists($beanFiles[$class])){ 580 require_once($beanFiles[$class]); 581 $mod = new $class(); 582 $installed = true; 583 $mod->custom_fields->addField($field['name'], $field['label'], $field['type'], $field['max_size'], $field['require_option'], $field['default_value'], $field['ext1'], $field['ext2'], $field['ext3'], $field['audited'], $field['mass_update'],$field['ext4'], $field['help'], $field['duplicate_merge']); 584 } 585 } 586 if(!$installed){ 587 $GLOBALS['log']->debug('Could not install custom field ' . $field['name'] . ' for module ' . $field['module'] . ': Module does not exist'); 588 } 589 } 590 } 591 592 function uninstall_custom_fields($fields){ 593 global $beanList, $beanFiles; 594 require_once ('modules/DynamicFields/DynamicField.php'); 595 $dyField = new DynamicField(); 596 597 foreach($fields as $field){ 598 $class = $beanList[ $field['module']]; 599 if(file_exists($beanFiles[$class])){ 600 require_once($beanFiles[$class]); 601 $mod = new $class(); 602 $dyField->bean = $mod; 603 $dyField->module = $field['module']; 604 $dyField->dropField($field['name']); 605 } 606 } 607 } 608 609 function install_relationships(){ 610 if(isset($this->installdefs['relationships'])){ 611 $this->log("Installing Relationships" ); 612 $str = "<?php \n //WARNING: The contents of this file are auto-generated\n"; 613 $save_table_dictionary = false; 614 foreach($this->installdefs['relationships'] as $relationship){ 615 616 $filename =basename($relationship['meta_data']); 617 $this->copy_path($relationship['meta_data'], 'metadata/'. $filename); 618 $this->install_relationship('metadata/'. $filename); 619 $save_table_dictionary = true; 620 $str .= "include_once('metadata/$filename');\n"; 621 if(!empty($relationship['module_vardefs'])){ 622 $relationship['module_vardefs'] = str_replace('<basepath>', $this->base_dir, $relationship['module_vardefs']); 623 $this->install_vardef($relationship['module_vardefs'], $relationship['module']); 624 } 625 if(!empty($relationship['module_layoutdefs'])){ 626 $relationship['module_layoutdefs'] = str_replace('<basepath>', $this->base_dir, $relationship['module_layoutdefs']); 627 $this->install_layoutdef($relationship['module_layoutdefs'], $relationship['module']); 628 } 629 } 630 $this->rebuild_vardefs(); 631 $this->rebuild_layoutdefs(); 632 if($save_table_dictionary){ 633 if(!file_exists("custom/Extension/application/Ext/TableDictionary")){ 634 mkdir_recursive("custom/Extension/application/Ext/TableDictionary", true); 635 } 636 $out = fopen("custom/Extension/application/Ext/TableDictionary/$this->id_name.php", 'w'); 637 fwrite($out,$str . "\n?>"); 638 fclose($out); 639 $this->rebuild_tabledictionary(); 640 } 641 642 643 } 644 } 645 function install_relationship($file){ 646 $_REQUEST['moduleInstaller'] = true; 647 if(!file_exists($file)){ 648 $GLOBALS['log']->debug( 'File does not exists : '.$file); 649 return; 650 } 651 include_once($file); 652 $rel_dictionary = $dictionary; 653 foreach ($rel_dictionary as $rel_name => $rel_data) 654 { 655 $table = $rel_data['table']; 656 657 658 659 if(!$this->db->tableExists($table)) 660 { 661 $this->db->createTableParams($table, $rel_data['fields'], $rel_data['indices']); 662 } 663 664 if(!$this->silent)$GLOBALS['log']->debug("Processing relationship meta for ". $rel_name."..."); 665 SugarBean::createRelationshipMeta($rel_name, $this->db,$table,$rel_dictionary,''); 666 Relationship::delete_cache(); 667 if(!$this->silent) $GLOBALS['log']->debug( 'done<br>'); 668 669 670 } 671 } 672 673 function uninstall_relationship($file){ 674 if(!file_exists($file)){ 675 $GLOBALS['log']->debug( 'File does not exists : '.$file); 676 return; 677 } 678 679 include_once($file); 680 $rel_dictionary = $dictionary; 681 foreach ($rel_dictionary as $rel_name => $rel_data) 682 { 683 if (isset($rel_data['table'])){ 684 $table = $rel_data['table']; 685 } 686 else{ 687 $table = ' One-to-Many '; 688 } 689 690 if ($this->db->tableExists($table)) 691 { 692 SugarBean::removeRelationshipMeta($rel_name, $this->db,$table,$rel_dictionary,''); 693 $this->db->dropTableName($table); 694 if(!$this->silent) $this->log( 'droping table ' . $table); 695 } 696 } 697 Relationship::delete_cache(); 698 } 699 700 function uninstall_relationships(){ 701 if(isset($this->installdefs['relationships'])){ 702 $this->log("Uninstalling Relationships" ); 703 foreach($this->installdefs['relationships'] as $relationship){ 704 $filename =basename($relationship['meta_data']); 705 if(isset($GLOBALS['mi_remove_tables']) && $GLOBALS['mi_remove_tables']) 706 $this->uninstall_relationship('metadata/'. $filename); 707 unlink( 'metadata/'. $filename); 708 //remove the vardefs 709 $path = 'custom/Extension/modules/' . $relationship['module']. '/Ext/Vardefs'; 710 if($relationship['module'] == 'application'){ 711 $path ='custom/Extension/' . $relationship['module']. '/Ext/Vardefs'; 712 } 713 if(!empty($relationship['module_vardefs']) && file_exists($path . '/'. $this->id_name . '.php')) 714 rmdir_recursive( $path . '/'. $this->id_name . '.php'); 715 //remove the layoutdefs 716 $path = 'custom/Extension/modules/' . $relationship['module']. '/Ext/Layoutdefs'; 717 if($relationship['module'] == 'application'){ 718 $path ='custom/Extension/' . $relationship['module']. '/Ext/Layoutdefs'; 719 } 720 721 if(!empty($relationship['module_layoutdefs']) && file_exists($path . '/'. $this->id_name . '.php')) 722 rmdir_recursive( $path . '/'. $this->id_name . '.php'); 723 } 724 if(file_exists("custom/Extension/application/Ext/TableDictionary/$this->id_name.php")){ 725 unlink("custom/Extension/application/Ext/TableDictionary/$this->id_name.php"); 726 } 727 $this->rebuild_tabledictionary(); 728 $this->rebuild_vardefs(); 729 $this->rebuild_layoutdefs(); 730 } 731 } 732 733 734 735 736 function uninstall($base_dir){ 737 global $app_strings; 738 $total_steps = 5; //min steps with no tasks 739 $current_step = 0; 740 $this->base_dir = $base_dir; 741 $tasks = array( 742 'pre_uninstall', 743 'uninstall_mkdirs', 744 'uninstall_copy', 745 'uninstall_menus', 746 'uninstall_dashlets', 747 'uninstall_userpage', 748 'uninstall_administration', 749 'uninstall_vardefs', 750 'uninstall_layoutdefs', 751 'uninstall_relationships', 752 'uninstall_languages', 753 'post_uninstall', 754 ); 755 $total_steps += count($tasks); //now the real number of steps 756 if(file_exists($this->base_dir . '/manifest.php')){ 757 if(!$this->silent){ 758 $current_step++; 759 display_progress_bar('install', $current_step, $total_steps); 760 echo '<div id ="displayLoglink" ><a href="#" onclick="toggleDisplay(\'displayLog\')">'.$app_strings['LBL_DISPLAY_LOG'].'</a> </div><div id="displayLog" style="display:none">'; 761 } 762 763 require_once($this->base_dir . '/manifest.php'); 764 $this->installdefs = $installdefs; 765 $this->id_name = $this->installdefs['id']; 766 $installed_modules = array(); 767 if(isset($this->installdefs['beans'])){ 768 769 foreach($this->installdefs['beans'] as $bean){ 770 771 $installed_modules[] = $bean['module']; 772 $this->uninstall_user_prefs($bean['module']); 773 774 775 } 776 777 $this->uninstall_beans($installed_modules); 778 if(!$this->silent){ 779 $current_step++; 780 update_progress_bar('install', $total_steps, $total_steps); 781 } 782 rmdir_recursive("custom/Extension/application/Ext/Include/$this->id_name.php"); 783 $this->merge_files('Ext/Include', 'modules.ext.php', '', true); 784 } 785 if(!$this->silent){ 786 $current_step++; 787 update_progress_bar('install', $current_step, $total_steps); 788 } 789 790 791 foreach($tasks as $task){ 792 $this->$task(); 793 if(!$this->silent){ 794 $current_step++; 795 update_progress_bar('install', $current_step, $total_steps); 796 } 797 } 798 if(isset($installdefs['custom_fields']) && (isset($GLOBALS['mi_remove_tables']) && $GLOBALS['mi_remove_tables'])){ 799 $this->log('Uninstalling Custom Fields...'); 800 $this->uninstall_custom_fields($installdefs['custom_fields']); 801 } 802 if(!$this->silent){ 803 $current_step++; 804 update_progress_bar('install', $current_step, $total_steps); 805 echo '</div>'; 806 } 807 $this->rebuild_relationships(); 808 if(!$this->silent){ 809 $current_step++; 810 update_progress_bar('install', $current_step, $total_steps); 811 echo '</div>'; 812 } 813 814 $this->log('Complete'); 815 update_progress_bar('install', $total_steps, $total_steps); 816 }else{ 817 die("No manifest.php Defined In $this->base_dir/manifest.php"); 818 } 819 } 820 821 function rebuild_languages($languages){ 822 foreach($languages as $language=>$value){ 823 $this->log("Rebuilding Language...$language"); 824 $this->merge_files('Ext/Language/', $language.'.lang.ext.php', $language); 825 } 826 sugar_cache_reset(); 827 } 828 829 function rebuild_vardefs(){ 830 $this->log("Rebuilding Vardefs..."); 831 $this->merge_files('Ext/Vardefs/', 'vardefs.ext.php'); 832 sugar_cache_reset(); 833 } 834 function rebuild_layoutdefs(){ 835 $this->log("Rebuilding Layoutdefs..."); 836 $this->merge_files('Ext/Layoutdefs/', 'layoutdefs.ext.php'); 837 838 } 839 840 function rebuild_menus(){ 841 $this->log("Rebuilding Menus..."); 842 $this->merge_files('Ext/Menus/', 'menu.ext.php'); 843 } 844 845 846 function rebuild_administration(){ 847 $this->log("Rebuilding administration Section..."); 848 $this->merge_files('Ext/Administration/', 'administration.ext.php'); 849 } 850 function rebuild_userpage(){ 851 $this->log("Rebuilding User Page Section..."); 852 $this->merge_files('Ext/UserPage/', 'userpage.ext.php'); 853 } 854 function rebuild_tabledictionary(){ 855 $this->log("Rebuilding administration Section..."); 856 $this->merge_files('Ext/TableDictionary/', 'tabledictionary.ext.php'); 857 } 858 859 function rebuild_relationships() { 860 echo 'Rebuilding Relationships'; 861 $_REQUEST['silent'] = true; 862 global $beanFiles; 863 include ('include/modules.php'); 864 include ("modules/Administration/RebuildRelationship.php"); 865 } 866 867 /** 868 * Wrapper call to modules/Administration/RepairIndex.php 869 */ 870 function repair_indices() { 871 global $current_user,$beanFiles,$dictionary; 872 $this->log('Repairing indexes'); 873 $_REQUEST['silent'] = true; // local var flagging echo'd output in repair script 874 $_REQUEST['mode'] = 'execute'; // flag to just go ahead and run the script 875 include ("modules/Administration/RepairIndex.php"); 876 } 877 878 function rebuild_all(){ 879 global $sugar_config; 880 881 $this->rebuild_languages($sugar_config['languages']); 882 $this->rebuild_vardefs(); 883 $this->rebuild_layoutdefs(); 884 $this->rebuild_menus(); 885 $this->rebuild_userpage(); 886 $this->rebuild_administration(); 887 $this->rebuild_relationships(); 888 $this->repair_indices(); 889 sugar_cache_reset(); 890 } 891 892 function merge_files($path, $name, $filter = '', $application = false){ 893 if(!$application){ 894 $GLOBALS['log']->debug("Merging module files for $name in $path"); 895 foreach($this->modules as $module){ 896 $GLOBALS['log']->debug("Merging Files for: ".$module); 897 $GLOBALS['log']->debug("Merging Files for path: ".$path); 898 $extension = "<?php \n //WARNING: The contents of this file are auto-generated\n"; 899 $extpath = "modules/$module/$path"; 900 $module_install = 'custom/Extension/'.$extpath; 901 $shouldSave = false; 902 if(is_dir($module_install)){ 903 $dir = dir($module_install); 904 $shouldSave = true; 905 while($entry = $dir->read()){ 906 if((empty($filter) || substr_count($entry, $filter) > 0) && is_file($module_install.'/'.$entry) && $entry != '.' && $entry != '..'){ 907 $fp = fopen($module_install . '/' . $entry, 'r'); 908 $file = fread($fp , filesize($module_install . '/' . $entry)); 909 fclose($fp); 910 $extension .= "\n". str_replace(array('<?php', '?>', '<?PHP', '<?'), array('','', '' ,'') , $file); 911 } 912 } 913 } 914 $extension .= "\n?>"; 915 916 if($shouldSave){ 917 if(!file_exists("custom/$extpath")){ 918 mkdir_recursive("custom/$extpath", true); 919 } 920 $out = fopen("custom/$extpath/$name", 'w'); 921 fwrite($out,$extension); 922 fclose($out); 923 }else{ 924 if(file_exists("custom/$extpath/$name")){ 925 unlink("custom/$extpath/$name"); 926 } 927 } 928 } 929 930 } 931 932 $GLOBALS['log']->debug("Merging application files for $name in $path"); 933 //Now the application stuff 934 $extension = "<?php \n //WARNING: The contents of this file are auto-generated\n"; 935 $extpath = "application/$path"; 936 $module_install = 'custom/Extension/'.$extpath; 937 $shouldSave = false; 938 if(is_dir($module_install)){ 939 $dir = dir($module_install); 940 while($entry = $dir->read()){ 941 $shouldSave = true; 942 if((empty($filter) || substr_count($entry, $filter) > 0) && is_file($module_install.'/'.$entry) && $entry != '.' && $entry != '..'){ 943 $fp = fopen($module_install . '/' . $entry, 'r'); 944 $file = fread($fp , filesize($module_install . '/' . $entry)); 945 fclose($fp); 946 $extension .= "\n". str_replace(array('<?php', '?>', '<?PHP', '<?'), array('','', '' ,'') , $file); 947 } 948 } 949 } 950 $extension .= "\n?>"; 951 if($shouldSave){ 952 if(!file_exists("custom/$extpath")){ 953 mkdir_recursive("custom/$extpath", true); 954 } 955 $out = fopen("custom/$extpath/$name", 'w'); 956 fwrite($out,$extension); 957 fclose($out); 958 }else{ 959 if(file_exists("custom/$extpath/$name")){ 960 unlink("custom/$extpath/$name"); 961 } 962 } 963 964 } 965 966 function install_beans($beans){ 967 include ('include/modules.php'); 968 foreach($beans as $bean){ 969 $this->log( "Installing Bean : $bean"); 970 if(isset($beanList[$bean])){ 971 $class = $beanList[$bean]; 972 if(file_exists($beanFiles[$class])){ 973 require_once($beanFiles[$class]); 974 $mod = new $class(); 975 if(is_subclass_of($mod, 'SugarBean')){ 976 $GLOBALS['log']->debug( "Creating Tables Bean : $bean"); 977 $mod->create_tables(); 978 SugarBean::createRelationshipMeta($mod->getObjectName(), $mod->db,$mod->table_name,'',$mod->module_dir); 979 } 980 }else{ 981 $GLOBALS['log']->debug( "File Does Not Exist:" . $beanFiles[$class] ); 982 } 983 } 984 } 985 } 986 987 function uninstall_beans($beans){ 988 include ('include/modules.php'); 989 foreach($beans as $bean){ 990 $this->log( "Uninstalling Bean : $bean"); 991 if(isset($beanList[$bean])){ 992 $class = $beanList[$bean]; 993 994 if(file_exists($beanFiles[$class])){ 995 require_once($beanFiles[$class]); 996 $mod = new $class(); 997 998 if(is_subclass_of($mod, 'SugarBean')){ 999 $GLOBALS['log']->debug( "Drop Tables : $bean"); 1000 if(isset($GLOBALS['mi_remove_tables']) && $GLOBALS['mi_remove_tables']) 1001 $mod->drop_tables(); 1002 } 1003 }else{ 1004 $GLOBALS['log']->debug( "File Does Not Exist:" . $beanFiles[$class] ); 1005 } 1006 } 1007 } 1008 } 1009 1010 function log($str){ 1011 $GLOBALS['log']->debug('ModuleInstaller:'. $str); 1012 if(!$this->silent){ 1013 echo $str . '<br>'; 1014 } 1015 } 1016 1017 /* BEGIN - RESTORE POINT - by MR. MILK August 31, 2005 02:15:18 PM */ 1018 function copy_recursive_with_backup( $source, $dest, $backup_path, $uninstall=false ) { 1019 1020 1021 1022 1023 1024 if(is_file($source)) { 1025 if($uninstall) { 1026 $GLOBALS['log']->debug("Restoring ... " . $source. " to " .$dest ); 1027 if(copy( $source, $dest)) { 1028 if(is_writable($dest)) 1029 touch( $dest, filemtime($source) ); 1030 return(unlink($source)); 1031 } 1032 else { 1033 $GLOBALS['log']->debug( "Can't restore file: " . $source ); 1034 return true; 1035 } 1036 } 1037 else { 1038 if(file_exists($dest)) { 1039 $rest = clean_path($backup_path."/$dest"); 1040 if( !is_dir(dirname($rest)) ) 1041 mkdir_recursive(dirname($rest), true); 1042 1043 $GLOBALS['log']->debug("Backup ... " . $dest. " to " .$rest ); 1044 if(copy( $dest, $rest)) { 1045 if(is_writable($rest)) 1046 touch( $rest, filemtime($dest) ); 1047 } 1048 else { 1049 $GLOBALS['log']->debug( "Can't backup file: " . $dest ); 1050 } 1051 } 1052 return( copy( $source, $dest ) ); 1053 } 1054 } 1055 elseif(!is_dir($source)) { 1056 if($uninstall) { 1057 if(is_file($dest)) 1058 return(unlink($dest)); 1059 else { 1060 rmdir_recursive($dest); 1061 return true; 1062 } 1063 } 1064 else 1065 return false; 1066 } 1067 1068 if( !is_dir($dest) && !$uninstall){ 1069 mkdir( $dest ); 1070 } 1071 1072 $status = true; 1073 1074 $d = dir( $source ); 1075 while( $f = $d->read() ){ 1076 if( $f == "." || $f == ".." ){ 1077 continue; 1078 } 1079 $status &= $this->copy_recursive_with_backup( "$source/$f", "$dest/$f", $backup_path, $uninstall ); 1080 } 1081 $d->close(); 1082 return( $status ); 1083 } 1084 /* END - RESTORE POINT - by MR. MILK August 31, 2005 02:15:34 PM */ 1085 1086 1087 /** 1088 * Static function which allows a module developer to abort their progress, pass in an array of errors and 1089 * redirect back to the main module loader page 1090 * 1091 * @param errors an array of error messages which will be displayed on the 1092 * main module loader page once it is loaded. 1093 */ 1094 function abort($errors = array()){ 1095 //set the errors onto the session so we can display them one the moduler loader page loads 1096 $_SESSION['MODULEINSTALLER_ERRORS'] = $errors; 1097 echo '<META HTTP-EQUIV="Refresh" content="0;url=index.php?module=Administration&action=UpgradeWizard&view=module">'; 1098 die(); 1099 //header('Location: index.php?module=Administration&action=UpgradeWizard&view=module'); 1100 } 1101 1102 /** 1103 * Return the set of errors stored in the SESSION 1104 * 1105 * @return an array of errors 1106 */ 1107 function getErrors(){ 1108 if(!empty($_SESSION['MODULEINSTALLER_ERRORS'])){ 1109 $errors = $_SESSION['MODULEINSTALLER_ERRORS']; 1110 unset($_SESSION['MODULEINSTALLER_ERRORS']); 1111 return $errors; 1112 } 1113 else 1114 return null; 1115 } 1116 1117 /////////////////// 1118 //********** DISABLE/ENABLE FUNCTIONS 1119 /////////////////// 1120 function enable($base_dir, $is_upgrade = false, $previous_version = ''){ 1121 global $app_strings; 1122 $this->base_dir = $base_dir; 1123 $total_steps = 3; //minimum number of steps with no tasks 1124 $current_step = 0; 1125 $tasks = array( 1126 'enable_copy', 1127 'enable_menus', 1128 'enable_userpage', 1129 'enable_dashlets', 1130 'enable_administration', 1131 'enable_vardefs', 1132 'enable_layoutdefs', 1133 'enable_relationships', 1134 'enable_languages', 1135 ); 1136 $total_steps += count($tasks); 1137 if(file_exists($this->base_dir . '/manifest.php')){ 1138 if(!$this->silent){ 1139 $current_step++; 1140 display_progress_bar('install', $current_step, $total_steps); 1141 echo '<div id ="displayLoglink" ><a href="#" onclick="toggleDisplay(\'displayLog\')">'.$app_strings['LBL_DISPLAY_LOG'].'</a> </div><div id="displayLog" style="display:none">'; 1142 } 1143 1144 require_once($this->base_dir . '/manifest.php'); 1145 if($is_upgrade && !empty($previous_version)){ 1146 //check if the upgrade path exists 1147 if(!empty($upgrade_manifest)){ 1148 if(!empty($upgrade_manifest['upgrade_paths'])){ 1149 if(!empty($upgrade_manifest['upgrade_paths'][$previous_version])){ 1150 $installdefs = $upgrade_manifest['upgrade_paths'][$previous_version]; 1151 }else{ 1152 $errors[] = 'No Upgrade Path Found in manifest.'; 1153 $this->abort($errors); 1154 }//fi 1155 }//fi 1156 }//fi 1157 }//fi 1158 $this->id_name = $installdefs['id']; 1159 $this->installdefs = $installdefs; 1160 $installed_modules = array(); 1161 if(isset($installdefs['beans'])){ 1162 1163 if(!file_exists("custom/Extension/application/Ext/Include")){ 1164 mkdir_recursive("custom/Extension/application/Ext/Include", true); 1165 } 1166 rename("custom/Extension/application/Ext/Include/".DISABLED_PATH.'/'. $this->id_name . '.php',"custom/Extension/application/Ext/Include/$this->id_name.php"); 1167 $this->merge_files('Ext/Include', 'modules.ext.php', '', true); 1168 } 1169 if(!$this->silent){ 1170 $current_step++; 1171 update_progress_bar('install', $current_step, $total_steps); 1172 } 1173 1174 foreach($tasks as $task){ 1175 $this->$task(); 1176 if(!$this->silent){ 1177 $current_step++; 1178 update_progress_bar('install', $current_step, $total_steps); 1179 } 1180 } 1181 1182 if(!$this->silent){ 1183 $current_step++; 1184 update_progress_bar('install', $current_step, $total_steps); 1185 echo '</div>'; 1186 } 1187 1188 $GLOBALS['log']->debug('Complete'); 1189 1190 }else{ 1191 die("No \$installdefs Defined In $this->base_dir/manifest.php"); 1192 } 1193 1194 } 1195 function disable($base_dir){ 1196 global $app_strings; 1197 $total_steps = 4; //min steps with no tasks 1198 $current_step = 0; 1199 $this->base_dir = $base_dir; 1200 $tasks = array( 1201 'disable_copy', 1202 'disable_menus', 1203 'disable_dashlets', 1204 'disable_userpage', 1205 'disable_administration', 1206 'disable_vardefs', 1207 'disable_layoutdefs', 1208 'disable_relationships', 1209 'disable_languages', 1210 ); 1211 $total_steps += count($tasks); //now the real number of steps 1212 if(file_exists($this->base_dir . '/manifest.php')){ 1213 if(!$this->silent){ 1214 $current_step++; 1215 display_progress_bar('install', $current_step, $total_steps); 1216 echo '<div id ="displayLoglink" ><a href="#" onclick="toggleDisplay(\'displayLog\')">'.$app_strings['LBL_DISPLAY_LOG'].'</a> </div><div id="displayLog" style="display:none">'; 1217 } 1218 1219 require_once($this->base_dir . '/manifest.php'); 1220 $this->installdefs = $installdefs; 1221 $this->id_name = $this->installdefs['id']; 1222 $installed_modules = array(); 1223 if(isset($this->installdefs['beans'])){ 1224 if(!$this->silent){ 1225 $current_step++; 1226 update_progress_bar('install', $total_steps, $total_steps); 1227 } 1228 mkdir_recursive("custom/Extension/application/Ext/Include/".DISABLED_PATH, true); 1229 rename("custom/Extension/application/Ext/Include/$this->id_name.php", "custom/Extension/application/Ext/Include/".DISABLED_PATH.'/'. $this->id_name . '.php'); 1230 $this->merge_files('Ext/Include', 'modules.ext.php', '', true); 1231 } 1232 if(!$this->silent){ 1233 $current_step++; 1234 update_progress_bar('install', $current_step, $total_steps); 1235 } 1236 foreach($tasks as $task){ 1237 $this->$task(); 1238 if(!$this->silent){ 1239 $current_step++; 1240 update_progress_bar('install', $current_step, $total_steps); 1241 } 1242 } 1243 if(!$this->silent){ 1244 $current_step++; 1245 update_progress_bar('install', $current_step, $total_steps); 1246 echo '</div>'; 1247 } 1248 1249 }else{ 1250 die("No manifest.php Defined In $this->base_dir/manifest.php"); 1251 } 1252 } 1253 function enable_vardef($to_module){ 1254 $GLOBALS['log']->debug("Enabling Vardefs ..." .$to_module); 1255 $path = 'custom/Extension/modules/' . $to_module. '/Ext/Vardefs'; 1256 if($to_module == 'application'){ 1257 $path ='custom/Extension/' . $to_module. '/Ext/Vardefs'; 1258 } 1259 if(!file_exists($path)){ 1260 mkdir_recursive($path, true); 1261 } 1262 rename($path . '/'.DISABLED_PATH.'/'. $this->id_name . '.php', $path . '/'. $this->id_name . '.php'); 1263 } 1264 function enable_vardefs(){ 1265 if(isset($this->installdefs['vardefs'])){ 1266 1267 foreach($this->installdefs['vardefs'] as $vardefs){ 1268 $vardefs['from'] = str_replace('<basepath>', $this->base_dir, $vardefs['from']); 1269 $GLOBALS['log']->debug("Enabling Vardefs ..." . $vardefs['from'] . " for " .$vardefs['to_module']); 1270 $path = 'custom/Extension/modules/' . $vardefs['to_module']. '/Ext/Vardefs'; 1271 if($vardefs['to_module'] == 'application'){ 1272 $path ='custom/Extension/' . $vardefs['to_module']. '/Ext/Vardefs'; 1273 } 1274 1275 rename( $path . '/'.DISABLED_PATH.'/'. $this->id_name . '.php', $path . '/'. $this->id_name . '.php'); 1276 } 1277 $this->rebuild_vardefs(); 1278 } 1279 } 1280 function disable_vardefs(){ 1281 $GLOBALS['log']->debug("Disabling Vardefs ".var_export($this->installdefs, true)); 1282 if(isset($this->installdefs['vardefs'])){ 1283 1284 foreach($this->installdefs['vardefs'] as $vardefs){ 1285 $vardefs['from'] = str_replace('<basepath>', $this->base_dir, $vardefs['from']); 1286 $GLOBALS['log']->debug("Disabling Vardefs ..." . $vardefs['from'] . " for " .$vardefs['to_module']); 1287 $path = 'custom/Extension/modules/' . $vardefs['to_module']. '/Ext/Vardefs'; 1288 if($vardefs['to_module'] == 'application'){ 1289 $path ='custom/Extension/' . $vardefs['to_module']. '/Ext/Vardefs'; 1290 } 1291 mkdir_recursive($path . '/'.DISABLED_PATH, true); 1292 rename( $path . '/'. $this->id_name . '.php', $path . '/'.DISABLED_PATH.'/'. $this->id_name . '.php'); 1293 } 1294 $this->rebuild_vardefs(); 1295 } 1296 } 1297 1298 function enable_relationships(){ 1299 if(isset($this->installdefs['relationships'])){ 1300 $str = "<?php \n //WARNING: The contents of this file are auto-generated\n"; 1301 $save_table_dictionary = false; 1302 foreach($this->installdefs['relationships'] as $relationship){ 1303 1304 $filename =basename($relationship['meta_data']); 1305 1306 $save_table_dictionary = true; 1307 $str .= "include_once('metadata/$filename');\n"; 1308 if(!empty($relationship['module_vardefs'])){ 1309 $this->enable_vardef($relationship['module']); 1310 } 1311 if(!empty($relationship['module_layoutdefs'])){ 1312 $this->enable_layoutdef($relationship['module']); 1313 } 1314 } 1315 $this->rebuild_vardefs(); 1316 $this->rebuild_layoutdefs(); 1317 if($save_table_dictionary){ 1318 if(!file_exists("custom/Extension/application/Ext/TableDictionary")){ 1319 mkdir_recursive("custom/Extension/application/Ext/TableDictionary", true); 1320 } 1321 rename("custom/Extension/application/Ext/TableDictionary/".DISABLED_PATH."/$this->id_name.php", "custom/Extension/application/Ext/TableDictionary/$this->id_name.php"); 1322 $this->rebuild_tabledictionary(); 1323 } 1324 1325 1326 } 1327 } 1328 1329 function disable_relationships($action = 'disable'){ 1330 if(isset($this->installdefs['relationships'])){ 1331 foreach($this->installdefs['relationships'] as $relationship){ 1332 $filename =basename($relationship['meta_data']); 1333 1334 1335 //remove the vardefs 1336 $path = 'custom/Extension/modules/' . $relationship['module']. '/Ext/Vardefs'; 1337 if($relationship['module'] == 'application'){ 1338 $path ='custom/Extension/' . $relationship['module']. '/Ext/Vardefs'; 1339 } 1340 if(!empty($relationship['module_vardefs']) && file_exists($path . '/'. $this->id_name . '.php')){ 1341 mkdir_recursive($path . '/'.DISABLED_PATH, true); 1342 rename( $path . '/'. $this->id_name . '.php', $path . '/'.DISABLED_PATH.'/'. $this->id_name . '.php'); 1343 } 1344 //remove the layoutdefs 1345 $path = 'custom/Extension/modules/' . $relationship['module']. '/Ext/Layoutdefs'; 1346 if($relationship['module'] == 'application'){ 1347 $path ='custom/Extension/' . $relationship['module']. '/Ext/Layoutdefs'; 1348 } 1349 1350 if(!empty($relationship['module_layoutdefs']) && file_exists($path . '/'. $this->id_name . '.php')){ 1351 mkdir_recursive($path . '/'.DISABLED_PATH, true); 1352 rename( $path . '/'. $this->id_name . '.php', $path . '/'.DISABLED_PATH.'/'. $this->id_name . '.php'); 1353 } 1354 1355 } 1356 if(file_exists("custom/Extension/application/Ext/TableDictionary/$this->id_name.php")){ 1357 mkdir_recursive("custom/Extension/application/Ext/TableDictionary/".DISABLED_PATH, true); 1358 rename("custom/Extension/application/Ext/TableDictionary/$this->id_name.php", "custom/Extension/application/Ext/TableDictionary/".DISABLED_PATH."/$this->id_name.php"); 1359 } 1360 $this->rebuild_tabledictionary(); 1361 $this->rebuild_vardefs(); 1362 $this->rebuild_layoutdefs(); 1363 } 1364 } 1365 1366 function enable_layoutdefs(){ 1367 if(isset($this->installdefs['layoutdefs'])){ 1368 foreach($this->installdefs['layoutdefs'] as $layoutdefs){ 1369 $this->enable_layoutdef($layoutdefs['to_module'], $this->id_name); 1370 } 1371 $this->rebuild_layoutdefs(); 1372 } 1373 } 1374 function enable_layoutdef($to_module){ 1375 $GLOBALS['log']->debug("Enabling Layout Defs ..." .$to_module); 1376 $path = 'custom/Extension/modules/' . $to_module. '/Ext/Layoutdefs'; 1377 if($to_module == 'application'){ 1378 $path ='custom/Extension/' . $to_module. '/Ext/Layoutdefs'; 1379 } 1380 if(!file_exists($path)){ 1381 mkdir_recursive($path, true); 1382 } 1383 rename($path . '/'.DISABLED_PATH.'/'. $this->id_name . '.php', $path . '/'. $this->id_name . '.php'); 1384 } 1385 1386 function disable_layoutdefs(){ 1387 if(isset($this->installdefs['layoutdefs'])){ 1388 1389 foreach($this->installdefs['layoutdefs'] as $layoutdefs){ 1390 $layoutdefs['from'] = str_replace('<basepath>', $this->base_dir, $layoutdefs['from']); 1391 $GLOBALS['log']->debug("Disabling Layoutdefs ..." . $layoutdefs['from'] . " for " .$layoutdefs['to_module']); 1392 $path = 'custom/Extension/modules/' . $layoutdefs['to_module']. '/Ext/Layoutdefs'; 1393 if($layoutdefs['to_module'] == 'application'){ 1394 $path ='custom/Extension/' . $layoutdefs['to_module']. '/Ext/Layoutdefs'; 1395 } 1396 mkdir_recursive($path . '/'.DISABLED_PATH, true); 1397 rename( $path . '/'. $this->id_name . '.php', $path . '/'.DISABLED_PATH.'/'. $this->id_name . '.php'); 1398 } 1399 $this->rebuild_layoutdefs(); 1400 } 1401 } 1402 1403 function enable_menus(){ 1404 if(isset($this->installdefs['menu'])){ 1405 foreach($this->installdefs['menu'] as $menu){ 1406 $menu['from'] = str_replace('<basepath>', $this->base_dir, $menu['from']); 1407 $GLOBALS['log']->debug("Enabling Menu ..." . $menu['from']. " for " .$menu['to_module'] ); 1408 $path = 'custom/Extension/modules/' . $menu['to_module']. '/Ext/Menus'; 1409 if($menu['to_module'] == 'application'){ 1410 $path ='custom/Extension/' . $menu['to_module']. '/Ext/Menus'; 1411 } 1412 if(!file_exists($path)){ 1413 mkdir_recursive($path, true); 1414 1415 } 1416 rename($path . '/'.DISABLED_PATH.'/'. $this->id_name . '.php', $path . '/'. $this->id_name . '.php'); 1417 } 1418 $this->rebuild_menus(); 1419 } 1420 1421 } 1422 1423 function disable_menus(){ 1424 if(isset($this->installdefs['menu'])){ 1425 foreach($this->installdefs['menu'] as $menu){ 1426 $menu['from'] = str_replace('<basepath>', $this->base_dir, $menu['from']); 1427 $GLOBALS['log']->debug("Disabling Menu ..." . $menu['from']. " for " .$menu['to_module'] ); 1428 $path = 'custom/Extension/modules/' . $menu['to_module']. '/Ext/Menus'; 1429 if($menu['to_module'] == 'application'){ 1430 $path ='custom/Extension/' . $menu['to_module']. '/Ext/Menus'; 1431 } 1432 mkdir_recursive($path . '/'.DISABLED_PATH, true); 1433 rename( $path . '/'. $this->id_name . '.php', $path . '/'.DISABLED_PATH.'/'. $this->id_name . '.php'); 1434 } 1435 $this->rebuild_menus(); 1436 } 1437 } 1438 1439 function enable_administration(){ 1440 if(isset($this->installdefs['administration'])){ 1441 foreach($this->installdefs['administration'] as $administration){ 1442 $administration['from'] = str_replace('<basepath>', $this->base_dir, $administration['from']); 1443 $GLOBALS['log']->debug("Installing Administration Section ..." . $administration['from'] ); 1444 $path = 'custom/Extension/modules/Administration/Ext/Administration'; 1445 if(!file_exists($path)){ 1446 mkdir_recursive($path, true); 1447 1448 } 1449 rename($path . '/'.DISABLED_PATH.'/'. $this->id_name . '.php', $path . '/'. $this->id_name . '.php'); 1450 } 1451 $this->rebuild_administration(); 1452 } 1453 1454 } 1455 function disable_administration(){ 1456 if(isset($this->installdefs['administration'])){ 1457 foreach($this->installdefs['administration'] as $administration){ 1458 $administration['from'] = str_replace('<basepath>', $this->base_dir, $administration['from']); 1459 $GLOBALS['log']->debug("Uninstalling Administration Section ..." . $administration['from'] ); 1460 $path = 'custom/Extension/modules/Administration/Ext/Administration'; 1461 mkdir_recursive($path . '/'.DISABLED_PATH, true); 1462 rename( $path . '/'. $this->id_name . '.php', $path . '/'.DISABLED_PATH.'/'. $this->id_name . '.php'); 1463 } 1464 $this->rebuild_administration(); 1465 } 1466 } 1467 1468 function enable_dashlets(){ 1469 if(isset($this->installdefs['dashlets'])){ 1470 foreach($this->installdefs['dashlets'] as $cp){ 1471 $cp['from'] = str_replace('<basepath>', $this->base_dir, $cp['from']); 1472 $path = 'custom/modules/Home/Dashlets/' . $cp['name'] . '/'; 1473 $disabled_path = 'custom/modules/Home/'.DISABLED_PATH.'Dashlets/' . $cp['name']; 1474 $GLOBALS['log']->debug("Enabling Dashlet " . $cp['name'] . "..." . $cp['from'] ); 1475 1476 rename($disabled_path, $path); 1477 } 1478 include ('modules/Administration/RebuildDashlets.php'); 1479 1480 } 1481 } 1482 1483 function disable_dashlets(){ 1484 if(isset($this->installdefs['dashlets'])){ 1485 foreach($this->installdefs['dashlets'] as $cp){ 1486 $path = 'custom/modules/Home/Dashlets/' . $cp['name']; 1487 $disabled_path = 'custom/modules/Home/'.DISABLED_PATH.'Dashlets/' . $cp['name']; 1488 $GLOBALS['log']->debug('Disabling ' .$path); 1489 mkdir_recursive('custom/modules/Home/'.DISABLED_PATH.'Dashlets/', true); 1490 rename( $path, $disabled_path); 1491 } 1492 include ('modules/Administration/RebuildDashlets.php'); 1493 } 1494 } 1495 1496 function enable_languages(){ 1497 $languages = array(); 1498 if(isset($this->installdefs['language'])){ 1499 foreach($this->installdefs['language'] as $packs){ 1500 $languages[$packs['language']] = $packs['language']; 1501 $packs['from'] = str_replace('<basepath>', $this->base_dir, $packs['from']); 1502 $GLOBALS['log']->debug("Installing Language Pack ..." . $packs['from'] . " for " .$packs['to_module']); 1503 $path = 'custom/Extension/modules/' . $packs['to_module']. '/Ext/Language'; 1504 if($packs['to_module'] == 'application'){ 1505 $path ='custom/Extension/' . $packs['to_module']. '/Ext/Language'; 1506 } 1507 1508 if(!file_exists($path)){ 1509 mkdir_recursive($path, true); 1510 1511 } 1512 rename($path.'/'.DISABLED_PATH.'/'.$packs['language'].'.'. $this->id_name . '.php', $path.'/'.$packs['language'].'.'. $this->id_name . '.php'); 1513 } 1514 $this->rebuild_languages($languages); 1515 1516 } 1517 } 1518 1519 function disable_languages(){ 1520 $languages = array(); 1521 if(isset($this->installdefs['language'])){ 1522 foreach($this->installdefs['language'] as $packs){ 1523 $languages[] = $packs['language']; 1524 $packs['from'] = str_replace('<basepath>', $this->base_dir, $packs['from']); 1525 $GLOBALS['log']->debug("Uninstalling Language Pack ..." . $packs['from'] . " for " .$packs['to_module']); 1526 $path = 'custom/Extension/modules/' . $packs['to_module']. '/Ext/Language'; 1527 if($packs['to_module'] == 'application'){ 1528 $path ='custom/Extension/' . $packs['to_module']. '/Ext/Language'; 1529 } 1530 mkdir_recursive($path . '/'.DISABLED_PATH, true); 1531 rename($path.'/'.$packs['language'].'.'. $this->id_name . '.php', $path.'/'.DISABLED_PATH.'/'.$packs['language'].'.'. $this->id_name . '.php'); 1532 } 1533 $this->rebuild_languages($languages); 1534 1535 } 1536 } 1537 1538 function enable_userpage(){ 1539 if(isset($this->installdefs['user_page'])){ 1540 foreach($this->installdefs['user_page'] as $userpage){ 1541 $userpage['from'] = str_replace('<basepath>', $this->base_dir, $userpage['from']); 1542 $GLOBALS['log']->debug("Installing User Page Section ..." . $userpage['from'] ); 1543 $path = 'custom/Extension/modules/Users/Ext/UserPage'; 1544 if(!file_exists($path)){ 1545 mkdir_recursive($path, true); 1546 1547 } 1548 rename($path . '/'.DISABLED_PATH.'/'. $this->id_name . '.php', $path . '/'. $this->id_name . '.php'); 1549 } 1550 $this->rebuild_userpage(); 1551 } 1552 1553 } 1554 function disable_userpage(){ 1555 if(isset($this->installdefs['user_page'])){ 1556 foreach($this->installdefs['user_page'] as $userpage){ 1557 $userpage['from'] = str_replace('<basepath>', $this->base_dir, $userpage['from']); 1558 $GLOBALS['log']->debug("Uninstalling User Page Section ..." . $userpage['from'] ); 1559 $path = 'custom/Extension/modules/Users/Ext/UserPage'; 1560 mkdir_recursive($path . '/'.DISABLED_PATH, true); 1561 rename( $path . '/'. $this->id_name . '.php', $path . '/'.DISABLED_PATH.'/'. $this->id_name . '.php'); 1562 } 1563 $this->rebuild_userpage(); 1564 } 1565 } 1566 1567 function enable_copy(){ 1568 //copy files back onto file system. first perform md5 check to determine if anything has been modified 1569 //here we should just go through the files in the -restore directory and copy those back 1570 if(isset($GLOBALS['mi_overwrite_files']) && $GLOBALS['mi_overwrite_files']){ 1571 if(!empty($this->installdefs['copy'])){ 1572 foreach($this->installdefs['copy'] as $cp){ 1573 $cp['to'] = clean_path(str_replace('<basepath>', $this->base_dir, $cp['to'])); 1574 $backup_path = clean_path( remove_file_extension(urldecode($_REQUEST['install_file']))."-restore/".$cp['to'] ); 1575 //check if this file exists in the -restore directory 1576 if(file_exists($backup_path)){ 1577 //since the file exists, then we want do an md5 of the install version and the file system version 1578 //if(is_file($backup_path) && md5_file($backup_path) == md5_file($cp['to'])){ 1579 //since the files are the same then we can safely move back from the -restore 1580 //directory into the file system 1581 $GLOBALS['log']->debug("ENABLE COPY:: FROM: ".$cp['from']. " TO: ".$cp['to']); 1582 $this->copy_path($cp['from'], $cp['to']); 1583 /*}else{ 1584 //since they are not equal then we need to prompt the user 1585 }*/ 1586 }//fi 1587 }//rof 1588 }//fi 1589 }//fi 1590 } 1591 1592 function disable_copy(){ 1593 //when we disable we want to copy the -restore files back into the file system 1594 //but we should check the version in the module install against the version on the file system 1595 //if they match then we can copy the file back, but otherwise we should ask the user. 1596 if(isset($GLOBALS['mi_overwrite_files']) && $GLOBALS['mi_overwrite_files']){ 1597 if(!empty($this->installdefs['copy'])){ 1598 foreach($this->installdefs['copy'] as $cp){ 1599 $cp['to'] = clean_path(str_replace('<basepath>', $this->base_dir, $cp['to'])); 1600 $backup_path = clean_path( remove_file_extension(urldecode($_REQUEST['install_file']))."-restore/".$cp['to'] ); 1601 //check if this file exists in the -restore directory 1602 if(file_exists($backup_path)){ 1603 //since the file exists, then we want do an md5 of the install version and the file system version 1604 $from = str_replace('<basepath>', $this->base_dir, $cp['from']); 1605 1606 //if(is_file($from) && md5_file($from) == md5_file($cp['to'])){ 1607 //since the files are the same then we can safely move back from the -restore 1608 //directory into the file system 1609 $GLOBALS['log']->debug("DISABLE COPY:: FROM: ".$backup_path. " TO: ".$cp['to']); 1610 $this->copy_path($backup_path, $cp['to']); 1611 /*}else{ 1612 //since they are not equal then we need to prompt the user 1613 }*/ 1614 }//fi 1615 }//rof 1616 }//fi 1617 }//fi 1618 } 1619 } 1620 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Tue Sep 11 10:48:47 2007 | par Balluche grâce à PHPXref 0.7 |