/modules/Administration/updateclass.php

https://github.com/joshbhamilton/sugarcrm_dev · PHP · 111 lines · 34 code · 6 blank · 71 comment · 7 complexity · 7b94b3e2fc1954869567c1b5cba55b9f MD5 · raw file

  1. <?php
  2. if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
  3. /*********************************************************************************
  4. * SugarCRM Community Edition is a customer relationship management program developed by
  5. * SugarCRM, Inc. Copyright (C) 2004-2011 SugarCRM Inc.
  6. *
  7. * This program is free software; you can redistribute it and/or modify it under
  8. * the terms of the GNU Affero General Public License version 3 as published by the
  9. * Free Software Foundation with the addition of the following permission added
  10. * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
  11. * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
  12. * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
  13. *
  14. * This program is distributed in the hope that it will be useful, but WITHOUT
  15. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  16. * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
  17. * details.
  18. *
  19. * You should have received a copy of the GNU Affero General Public License along with
  20. * this program; if not, see http://www.gnu.org/licenses or write to the Free
  21. * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  22. * 02110-1301 USA.
  23. *
  24. * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
  25. * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
  26. *
  27. * The interactive user interfaces in modified source and object code versions
  28. * of this program must display Appropriate Legal Notices, as required under
  29. * Section 5 of the GNU Affero General Public License version 3.
  30. *
  31. * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
  32. * these Appropriate Legal Notices must retain the display of the "Powered by
  33. * SugarCRM" logo. If the display of the logo is not reasonably feasible for
  34. * technical reasons, the Appropriate Legal Notices must display the words
  35. * "Powered by SugarCRM".
  36. ********************************************************************************/
  37. require("include/modules.php");
  38. require_once("include/utils/sugar_file_utils.php");
  39. foreach ($beanFiles as $classname => $filename){
  40. if (file_exists($filename)){
  41. // Rename the class and its constructor adding SugarCore at the beginning (Ex: class SugarCoreCall)
  42. $handle = file_get_contents($filename);
  43. $patterns = array ('/class '.$classname.'/','/function '.$classname.'/');
  44. $replace = array ('class SugarCore'.$classname,'function SugarCore'.$classname);
  45. $data = preg_replace($patterns,$replace, $handle);
  46. sugar_file_put_contents($filename,$data);
  47. // Rename the SugarBean file into SugarCore.SugarBean (Ex: SugarCore.Call.php)
  48. $pos=strrpos($filename,"/");
  49. $newfilename=substr_replace($filename, 'SugarCore.', $pos+1, 0);
  50. sugar_rename($filename,$newfilename);
  51. //Create a new SugarBean that extends CoreBean
  52. $fileHandle = sugar_fopen($filename, 'w') ;
  53. $newclass = <<<FABRICE
  54. <?php
  55. if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
  56. /*********************************************************************************
  57. * SugarCRM Community Edition is a customer relationship management program developed by
  58. * SugarCRM, Inc. Copyright (C) 2004-2011 SugarCRM Inc.
  59. *
  60. * This program is free software; you can redistribute it and/or modify it under
  61. * the terms of the GNU Affero General Public License version 3 as published by the
  62. * Free Software Foundation with the addition of the following permission added
  63. * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
  64. * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
  65. * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
  66. *
  67. * This program is distributed in the hope that it will be useful, but WITHOUT
  68. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  69. * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
  70. * details.
  71. *
  72. * You should have received a copy of the GNU Affero General Public License along with
  73. * this program; if not, see http://www.gnu.org/licenses or write to the Free
  74. * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  75. * 02110-1301 USA.
  76. *
  77. * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
  78. * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
  79. *
  80. * The interactive user interfaces in modified source and object code versions
  81. * of this program must display Appropriate Legal Notices, as required under
  82. * Section 5 of the GNU Affero General Public License version 3.
  83. *
  84. * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
  85. * these Appropriate Legal Notices must retain the display of the "Powered by
  86. * SugarCRM" logo. If the display of the logo is not reasonably feasible for
  87. * technical reasons, the Appropriate Legal Notices must display the words
  88. * "Powered by SugarCRM".
  89. ********************************************************************************/
  90. if(!class_exists('$classname')){
  91. if (file_exists('custom/$filename')){
  92. require('custom/$filename');
  93. }
  94. else{
  95. require('$newfilename');
  96. class $classname extends SugarCore$classname{}
  97. }
  98. }
  99. ?>
  100. FABRICE;
  101. fwrite($fileHandle, $newclass);
  102. fclose($fileHandle);
  103. }
  104. }
  105. ?>