[ Index ]
 

Code source de SugarCRM 5.0.0beta1

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/ModuleInstall/PackageManager/ -> PackageManager.php (source)

   1  <?php
   2  /*********************************************************************************

   3   * SugarCRM is a customer relationship management program developed by

   4   * SugarCRM, Inc. Copyright (C) 2004 - 2007 SugarCRM Inc.

   5   * 

   6   * This program is free software; you can redistribute it and/or modify it under

   7   * the terms of the GNU General Public License version 3 as published by the

   8   * Free Software Foundation.

   9   * 

  10   * This program is distributed in the hope that it will be useful, but WITHOUT

  11   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS

  12   * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more

  13   * details.

  14   * 

  15   * You should have received a copy of the GNU General Public License along with

  16   * this program; if not, see http://www.gnu.org/licenses or write to the Free

  17   * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA

  18   * 02110-1301 USA.

  19   * 

  20   * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,

  21   * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.

  22   * 

  23   * The interactive user interfaces in modified source and object code versions

  24   * of this program must display Appropriate Legal Notices, as required under

  25   * Section 5 of the GNU General Public License version 3.

  26   * 

  27   * In accordance with Section 7(b) of the GNU General Public License version 3,

  28   * these Appropriate Legal Notices must retain the display of the "Powered by

  29   * SugarCRM" logo. If the display of the logo is not reasonably feasible for

  30   * technical reasons, the Appropriate Legal Notices must display the words

  31   * "Powered by SugarCRM".

  32   ********************************************************************************/
  33  
  34  define("CREDENTIAL_CATEGORY", "ml");
  35  define("CREDENTIAL_USERNAME", "username");
  36  define("CREDENTIAL_PASSWORD", "password");
  37  
  38  require_once ('include/dir_inc.php');
  39  require_once ('include/utils/file_utils.php');
  40  include_once  ('include/database/DBManagerFactory.php');
  41  require_once ('modules/Relationships/Relationship.php');
  42  require_once ('include/nusoap/nusoap.php');
  43  require_once ('include/utils/file_utils.php');
  44  require_once ('include/utils/zip_utils.php');
  45  require_once ('include/utils.php');
  46  require_once ('ModuleInstall/PackageManager/PackageManagerDisplay.php');
  47  require_once ('ModuleInstall/ModuleInstaller.php');
  48  require_once ('modules/Administration/UpgradeHistory.php');
  49  require_once ('include/entryPoint.php');
  50  require_once ('ModuleInstall/PackageManager/PackageManagerComm.php');
  51  
  52  
  53   class PackageManager{
  54      var $soap_client;
  55      
  56      /**

  57       * Constructor: In this method we will initialize the nusoap client to point to the hearbeat server

  58       */
  59      function PackageManager(){
  60          $this->db = & DBManagerFactory::getInstance();   
  61      }
  62      
  63      function initializeComm(){
  64          
  65      }
  66         
  67      /**

  68       * Obtain a promotion from SugarDepot

  69       * @return string   the string from the promotion

  70       */
  71      function getPromotion(){
  72          $name_value_list = PackageManagerComm::getPromotion();
  73          if(!empty($name_value_list)){
  74              $name_value_list = PackageManager::fromNameValueList($name_value_list);
  75              return $name_value_list['description'];
  76          }else {
  77             return '';
  78          }   
  79      }
  80      
  81      /**

  82       * Obtain a list of category/packages/releases for use within the module loader

  83       */
  84      function getModuleLoaderCategoryPackages($category_id = ''){
  85          $filter = array();
  86          $filter = array('type' => "'module', 'theme', 'langpack'");
  87          $filter = PackageManager::toNameValueList($filter);
  88          return PackageManager::getCategoryPackages($category_id, $filter);
  89      }
  90      
  91      /**

  92       * Obtain the list of category_packages from SugarDepot

  93       * @return category_packages

  94       */
  95      function getCategoryPackages($category_id = '', $filter = array()){
  96           $results = PackageManagerComm::getCategoryPackages($category_id, $filter);
  97           PackageManagerComm::errorCheck();
  98           $nodes = array();
  99  
 100          $nodes[$category_id]['packages'] = array();
 101          if(!empty($results['categories'])){
 102               foreach($results['categories'] as $category){
 103                  $mycat = PackageManager::fromNameValueList($category);
 104                  $nodes[$mycat['id']] = array('id' => $mycat['id'], 'label' => $mycat['name'], 'description' => $mycat['description'], 'type' => 'cat', 'parent' => $mycat['parent_id']);       
 105                  $nodes[$mycat['id']]['packages'] = array();
 106               }
 107          }
 108           if(!empty($results['packages'])){
 109              $uh = new UpgradeHistory();
 110               foreach($results['packages'] as $package){
 111                  $mypack = PackageManager::fromNameValueList($package);
 112                  $nodes[$mypack['category_id']]['packages'][$mypack['id']] = array('id' => $mypack['id'], 'label' => $mypack['name'], 'description' => $mypack['description'], 'category_id' => $mypack['category_id'], 'type' => 'package');       
 113                  $releases = PackageManager::getReleases($category_id, $mypack['id'], $filter);
 114                  $arr_releases = array();
 115                  $nodes[$mypack['category_id']]['packages'][$mypack['id']]['releases'] = array();
 116                  if(!empty($releases['packages'])){
 117                      foreach($releases['packages'] as $release){                
 118                           $myrelease = PackageManager::fromNameValueList($release);
 119                           //check to see if we already this one installed

 120                           $result = $uh->determineIfUpgrade($myrelease['id_name'], $myrelease['version']);
 121                           $enable = false;
 122                           if($result == true || is_array($result))
 123                               $enable = true;
 124                           $nodes[$mypack['category_id']]['packages'][$mypack['id']]['releases'][$myrelease['id']] = array('id' => $myrelease['id'], 'version' => $myrelease['version'], 'label' => $myrelease['description'], 'category_id' => $mypack['category_id'], 'package_id' => $mypack['id'], 'type' => 'release', 'enable' => $enable);               
 125                         }  
 126                  }
 127                  //array_push($nodes[$mypack['category_id']]['packages'], $package_arr);

 128               }   
 129           }
 130           $GLOBALS['log']->debug("NODES". var_export($nodes, true));
 131          return $nodes;
 132      }
 133      
 134      /**

 135       * Get a list of categories from the SugarDepot

 136       * @param category_id   the category id of parent to obtain

 137       * @param filter        an array of filters to pass to limit the query

 138       * @return array        an array of categories for display on the client

 139       */
 140      function getCategories($category_id, $filter = array()){
 141          $nodes = array();
 142          $results = PackageManagerComm::getCategories($category_id, $filter);
 143          PackageManagerComm::errorCheck();
 144          if(!empty($results['categories'])){
 145              foreach($results['categories'] as $category){
 146                  $mycat = PackageManager::fromNameValueList($category);
 147                  $nodes[] = array('id' => $mycat['id'], 'label' => $mycat['name'], 'description' => $mycat['description'], 'type' => 'cat', 'parent' => $mycat['parent_id']);       
 148              }  
 149          }
 150          return $nodes;       
 151      }
 152      
 153      function getPackages($category_id, $filter = array()){
 154          $nodes = array();
 155          $results = PackageManagerComm::getPackages($category_id, $filter);
 156          PackageManagerComm::errorCheck();
 157          $packages = array();
 158          //$xml = '';

 159          //$xml .= '<packages>';

 160          if(!empty($results['packages'])){
 161              foreach($results['packages'] as $package){
 162                  $mypack = PackageManager::fromNameValueList($package);
 163                  $packages[$mypack['id']] = array('package_id' => $mypack['id'], 'name' => $mypack['name'], 'description' => $mypack['description'], 'category_id' => $mypack['category_id']);
 164                  $releases = PackageManager::getReleases($category_id, $mypack['id']);
 165                  $arr_releases = array();
 166                  foreach($releases['packages'] as $release){                
 167                       $myrelease = PackageManager::fromNameValueList($release);
 168                       $arr_releases[$myrelease['id']]  = array('release_id' => $myrelease['id'], 'version' => $myrelease['version'], 'description' => $myrelease['description'], 'category_id' => $mypack['category_id'], 'package_id' => $mypack['id']);               
 169                  }  
 170                  $packages[$mypack['id']]['releases'] = $arr_releases;            
 171              }  
 172          }
 173          return $packages;    
 174      }
 175      
 176      function getReleases($category_id, $package_id, $filter = array()){
 177          $releases = PackageManagerComm::getReleases($category_id, $package_id, $filter);
 178          PackageManagerComm::errorCheck();  
 179          return $releases;
 180      }
 181      
 182      /**

 183       * Retrieve the package as specified by the $id from the heartbeat server

 184       *

 185       * @param category_id   the category_id to which the release belongs

 186       * @param package_id    the package_id to which the release belongs 

 187       * @param release_id    the release_id to download   

 188       * @return filename - the path to which the zip file was saved

 189       */
 190      function download($category_id, $package_id, $release_id, $save_dir = ''){
 191          $GLOBALS['log']->debug('RELEASE _ID: '.$release_id);
 192          if(!empty($release_id)){
 193              $filename = PackageManagerComm::addDownload($category_id, $package_id, $release_id);
 194              if($filename){
 195                  $GLOBALS['log']->debug('RESULT: '.$filename);
 196                  PackageManagerComm::errorCheck();
 197                     $filepath = PackageManagerComm::performDownload($filename, $save_dir);
 198                     return $filepath;
 199                  /*if(!empty($result) && !empty($result['filename']) && !empty($save_dir)){

 200                      $GLOBALS['log']->debug('Saving Package to: '.$save_dir);   

 201                      $GLOBALS['log']->debug('Saving package to the local file system:'.$result['filename']);

 202                      return write_encoded_file ($result, $save_dir);

 203                  }else{

 204                      return null;

 205                  }*/
 206              }
 207          }else{
 208              return null;
 209          }
 210      }
 211      
 212      /**

 213       * Given the Mambo username, password, and download key attempt to authenticate, if 

 214       * successful then store these credentials

 215       * 

 216       * @param username      Mambo username

 217       * @param password      Mambo password

 218       * @param systemname   the user's download key

 219       * @return              true if successful, false otherwise   

 220       */
 221      function authenticate($username, $password, $systemname='', $terms_checked = true){
 222          PackageManager::setCredentials($username, $password, $systemname);
 223          PackageManagerComm::clearSession();
 224          $result = PackageManagerComm::login($terms_checked); 
 225          if(is_array($result))
 226              return $result;    
 227             else
 228              return true;
 229      }
 230      
 231      function setCredentials($username, $password, $systemname){
 232           require_once ("modules/Administration/Administration.php");
 233          $admin = new Administration();
 234          $admin->retrieveSettings();    
 235           $admin->saveSetting(CREDENTIAL_CATEGORY, CREDENTIAL_USERNAME, $username);
 236           $admin->saveSetting(CREDENTIAL_CATEGORY, CREDENTIAL_PASSWORD, $password);
 237           if(!empty($systemname)){
 238               $admin->saveSetting('system', 'name', $systemname);
 239           }
 240      }
 241      
 242      function getCredentials(){
 243           require_once ("modules/Administration/Administration.php");
 244          $admin = new Administration();
 245          $admin->retrieveSettings(CREDENTIAL_CATEGORY, true);
 246          $credentials = array();
 247          $credentials['username'] = '';
 248          $credentials['password'] = '';
 249          $credentials['system_name'] = '';
 250          if(!empty($admin->settings[CREDENTIAL_CATEGORY.'_'.CREDENTIAL_USERNAME])){
 251             $credentials['username'] = $admin->settings[CREDENTIAL_CATEGORY.'_'.CREDENTIAL_USERNAME];
 252          }
 253          if(!empty($admin->settings[CREDENTIAL_CATEGORY.'_'.CREDENTIAL_USERNAME])){
 254             $credentials['password'] = $admin->settings[CREDENTIAL_CATEGORY.'_'.CREDENTIAL_PASSWORD];
 255          }
 256          if(!empty($admin->settings['system_name'])){
 257             $credentials['system_name'] = $admin->settings['system_name'];
 258          }
 259          return $credentials;
 260      }
 261      
 262      function getTermsAndConditions(){
 263          return PackageManagerComm::getTermsAndConditions();
 264          
 265      }
 266      
 267      /**

 268       * Retrieve documentation for the given release or package

 269       * 

 270       * @param package_id    the specified package to retrieve documentation

 271       * @param release_id    the specified release to retrieve documentation

 272       * 

 273       * @return documents

 274       */
 275      function getDocumentation($package_id, $release_id){
 276           if(!empty($release_id) || !empty($package_id)){
 277              $documents = PackageManagerComm::getDocumentation($package_id, $release_id);
 278              return $documents;
 279          }else{
 280              return null;
 281          }        
 282      }
 283         
 284      /**

 285       * Grab the list of installed modules and send that list to the depot.

 286       * The depot will then send back a list of modules that need to be updated

 287       */
 288      function checkForUpdates(){
 289          $lists = $this->buildInstalledReleases(array('module'), true);
 290          $updates = array();
 291          if(!empty($lists)){
 292              $updates = PackageManagerComm::checkForUpdates($lists);
 293          }//fi

 294          return $updates;                
 295      }
 296           
 297       ////////////////////////////////////////////////////////

 298       /////////// HELPER FUNCTIONS

 299      function toNameValueList($array){
 300          $list = array();    
 301          foreach($array as $name=>$value){
 302              $list[] = array('name'=>$name, 'value'=>$value);
 303          }
 304          return $list;
 305      }
 306      
 307  	function toNameValueLists($arrays){
 308          $lists = array();
 309          foreach($arrays as $array){
 310              $lists[] = PackageManager::toNameValueList($array);
 311          }
 312          return $lists;
 313      }
 314      
 315       function fromNameValueList($nvl){
 316          $array = array();
 317          foreach($nvl as $list){
 318              $array[$list['name']] = $list['value'];
 319          }
 320          return $array;
 321      }
 322      
 323      function buildInstalledReleases($types = array('module')){
 324          //1) get list of installed modules

 325          $installeds = $this->getInstalled($types);
 326          $releases = array();
 327          foreach($installeds as $installed){
 328              $releases[] = array('name' => $installed->name, 'id_name' => $installed->id_name, 'version' => $installed->version, 'filename' => $installed->filename, 'type' => $installed->type);
 329          }
 330          
 331          $lists = array();
 332          $name_value_list = array();
 333          if(!empty($releases)){
 334              $lists = $this->toNameValueLists($releases);        
 335          }//fi    

 336          return $lists;
 337      }
 338      
 339      function buildPackageXML($package, $releases = array()){
 340          $xml = '<package>';
 341          $xml .= '<package_id>'.$package['id'].'</package_id>';
 342          $xml .= '<name>'.$package['name'].'</name>';
 343          $xml .= '<description>'.$package['description'].'</description>';
 344          if(!empty($releases)){
 345               $xml .= '<releases>';
 346               foreach($releases['packages'] as $release){ 
 347                 
 348                   $myrelease = PackageManager::fromNameValueList($release);
 349                   $xml .= '<release>';
 350                   $xml .= '<release_id>'.$myrelease['id'].'</release_id>';
 351                   $xml .= '<version>'.$myrelease['version'].'</version>';
 352                   $xml .= '<description>'.$myrelease['description'].'</description>';
 353                   $xml .= '<package_id>'.$package['id'].'</package_id>';
 354                   $xml .= '<category_id>'.$package['category_id'].'</category_id>';
 355                   $xml .= '</release>';      
 356               }  
 357               $xml .= '</releases>';    
 358          }
 359          $xml .= '</package>';   
 360          return $xml; 
 361      }
 362         
 363      //////////////////////////////////////////////////////////////////////

 364      /////////// INSTALL SECTION

 365      function extractFile( $zip_file, $file_in_zip, $base_tmp_upgrade_dir){
 366          $my_zip_dir = mk_temp_dir( $base_tmp_upgrade_dir );
 367          unzip_file( $zip_file, $file_in_zip, $my_zip_dir );
 368          return( "$my_zip_dir/$file_in_zip" );
 369      }
 370  
 371      function extractManifest( $zip_file,$base_tmp_upgrade_dir ) {
 372          return( $this->extractFile( $zip_file, "manifest.php",$base_tmp_upgrade_dir ) );
 373      }
 374      
 375      function validate_manifest( $manifest ){
 376      // takes a manifest.php manifest array and validates contents

 377      global $subdirs;
 378      global $sugar_version;
 379      global $sugar_flavor;
 380      global $mod_strings;
 381  
 382      if( !isset($manifest['type']) ){
 383          die($mod_strings['ERROR_MANIFEST_TYPE']);
 384      }
 385      $type = $manifest['type'];
 386      $GLOBALS['log']->debug("Getting InstallType");
 387      if( $this->getInstallType( "/$type/" ) == "" ){
 388          $GLOBALS['log']->debug("Error with InstallType".$type);
 389          die($mod_strings['ERROR_PACKAGE_TYPE']. ": '" . $type . "'." );
 390      }
 391      $GLOBALS['log']->debug("Passed with InstallType");
 392      if( isset($manifest['acceptable_sugar_versions']) ){
 393              $version_ok = false;
 394              $matches_empty = true;
 395              if( isset($manifest['acceptable_sugar_versions']['exact_matches']) ){
 396                  $matches_empty = false;
 397                  foreach( $manifest['acceptable_sugar_versions']['exact_matches'] as $match ){
 398                      if( $match == $sugar_version ){
 399                          $version_ok = true;
 400                      }
 401                  }
 402              }
 403              if( !$version_ok && isset($manifest['acceptable_sugar_versions']['regex_matches']) ){
 404                  $matches_empty = false;
 405                  foreach( $manifest['acceptable_sugar_versions']['regex_matches'] as $match ){
 406                      if( preg_match( "/$match/", $sugar_version ) ){
 407                          $version_ok = true;
 408                      }
 409                  }
 410              }
 411      
 412              if( !$matches_empty && !$version_ok ){
 413                  die( $mod_strings['ERROR_VERSION_INCOMPATIBLE'] . $sugar_version );
 414              }
 415          }
 416      
 417       if( isset($manifest['acceptable_sugar_flavors']) && sizeof($manifest['acceptable_sugar_flavors']) > 0 ){
 418              $flavor_ok = false;
 419              foreach( $manifest['acceptable_sugar_flavors'] as $match ){
 420                  if( $match == $sugar_flavor ){
 421                      $flavor_ok = true;
 422                  }
 423              }
 424              if( !$flavor_ok ){
 425                  //die( $mod_strings['ERROR_FLAVOR_INCOMPATIBLE'] . $sugar_version );

 426              }
 427          }
 428      }
 429      
 430      function getInstallType( $type_string ){
 431          // detect file type

 432          global $subdirs;
 433          $subdirs = array('full', 'langpack', 'module', 'patch', 'theme', 'temp');
 434  
 435          
 436          foreach( $subdirs as $subdir ){
 437              if( preg_match( "#/$subdir/#", $type_string ) ){
 438                  return( $subdir );
 439              }
 440          }
 441          // return empty if no match

 442          return( "" );
 443      }
 444      
 445      function performSetup($tempFile, $view = 'module', $display_messages = true){       
 446          global $sugar_config;
 447          $base_filename = urldecode($tempFile);
 448          $GLOBALS['log']->debug("BaseFileName: ".$base_filename);
 449          $base_upgrade_dir       = $sugar_config['upload_dir'] . "/upgrades";
 450          $base_tmp_upgrade_dir   = "$base_upgrade_dir/temp";
 451          $manifest_file = $this->extractManifest( $base_filename,$base_tmp_upgrade_dir);
 452           $GLOBALS['log']->debug("Manifest: ".$manifest_file);
 453          if($view == 'module')
 454              $license_file = $this->extractFile($base_filename, 'LICENSE.txt', $base_tmp_upgrade_dir);
 455          if(is_file($manifest_file)){
 456              $GLOBALS['log']->debug("VALIDATING MANIFEST". $manifest_file);
 457              require_once( $manifest_file );
 458              $this->validate_manifest($manifest );
 459              $upgrade_zip_type = $manifest['type'];
 460              $GLOBALS['log']->debug("VALIDATED MANIFEST");
 461              // exclude the bad permutations

 462              if( $view == "module" ){
 463                  if ($upgrade_zip_type != "module" && $upgrade_zip_type != "theme" && $upgrade_zip_type != "langpack"){
 464                      $this->unlinkTempFiles();
 465                      if($display_messages)
 466                          die($mod_strings['ERR_UW_NOT_ACCEPTIBLE_TYPE']);
 467                  }
 468              }elseif( $view == "default" ){
 469                  if($upgrade_zip_type != "patch" ){
 470                      $this->unlinkTempFiles();
 471                      if($display_messages)
 472                          die($mod_strings['ERR_UW_ONLY_PATCHES']);
 473                  }
 474              }
 475      
 476              $base_filename = preg_replace( "#\\\\#", "/", $base_filename );
 477              $base_filename = basename( $base_filename );
 478              mkdir_recursive( "$base_upgrade_dir/$upgrade_zip_type" );
 479              $target_path = "$base_upgrade_dir/$upgrade_zip_type/$base_filename";
 480              $target_manifest = remove_file_extension( $target_path ) . "-manifest.php";
 481      
 482              if( isset($manifest['icon']) && $manifest['icon'] != "" ){
 483                  $icon_location = $this->extractFile( $tempFile ,$manifest['icon'], $base_tmp_upgrade_dir );
 484                  $path_parts = pathinfo( $icon_location );
 485                  copy( $icon_location, remove_file_extension( $target_path ) . "-icon." . $path_parts['extension'] );
 486              }
 487      
 488              if( copy( $tempFile , $target_path ) ){
 489                  copy( $manifest_file, $target_manifest );
 490                  if($display_messages)
 491                      echo $base_filename.$mod_strings['LBL_UW_UPLOAD_SUCCESS'];
 492              }else{
 493                  if($display_messages)
 494                      echo $mod_strings['ERR_UW_UPLOAD_ERROR'];
 495              }
 496          }//fi

 497          else{
 498              $this->unlinkTempFiles();
 499              if($display_messages)
 500                  die($mod_strings['ERR_UW_NO_MANIFEST']);
 501          }    
 502      }
 503      
 504      function unlinkTempFiles() {
 505          global $sugar_config;
 506          @unlink($_FILES['upgrade_zip']['tmp_name']);
 507          @unlink(getcwd().'/'.$sugar_config['upload_dir'].$_FILES['upgrade_zip']['name']);
 508      }
 509      
 510      function performInstall($file){
 511          global $sugar_config;
 512          global $mod_strings;
 513          $base_upgrade_dir       = $sugar_config['upload_dir'] . "/upgrades";
 514          $base_tmp_upgrade_dir   = "$base_upgrade_dir/temp";
 515          
 516          $GLOBALS['log']->debug("INSTALLING: ".$file);
 517          $mi = new ModuleInstaller();
 518          $mi->silent = true;
 519          $mod_strings = return_module_language('en', "Administration");
 520               $GLOBALS['log']->debug("ABOUT TO INSTALL: ".$file);
 521          if(preg_match("#.*\.zip\$#", $file)) {
 522               $GLOBALS['log']->debug("1: ".$file);
 523              // handle manifest.php

 524              $target_manifest = remove_file_extension( $file ) . '-manifest.php';
 525              include($target_manifest);  
 526              $GLOBALS['log']->debug("2: ".$file);          
 527              $unzip_dir = mk_temp_dir( $base_tmp_upgrade_dir ); 
 528              unzip($file, $unzip_dir );
 529              $GLOBALS['log']->debug("3: ".$unzip_dir);
 530              $id_name = $installdefs['id'];
 531              $version = $manifest['version'];
 532              $uh = new UpgradeHistory();
 533              $previous_install = array();
 534              if(!empty($id_name) & !empty($version))
 535                  $previous_install = $uh->determineIfUpgrade($id_name, $version);
 536              $previous_version = (empty($previous_install['version'])) ? '' : $previous_install['version'];
 537              $previous_id = (empty($previous_install['id'])) ? '' : $previous_install['id'];
 538              
 539              if(!empty($previous_version)){
 540                  $mi->install($unzip_dir, true, $previous_version);
 541              }else{
 542                  $mi->install($unzip_dir);
 543              }
 544              $GLOBALS['log']->debug("INSTALLED: ".$file);
 545              $new_upgrade = new UpgradeHistory();
 546              $new_upgrade->filename      = $file;
 547              $new_upgrade->md5sum        = md5_file($file);
 548              $new_upgrade->type          = $manifest['type'];
 549              $new_upgrade->version       = $manifest['version'];
 550              $new_upgrade->status        = "installed";
 551              //$new_upgrade->author        = $manifest['author'];

 552              $new_upgrade->name          = $manifest['name'];
 553              $new_upgrade->description   = $manifest['description'];
 554              $new_upgrade->id_name        = $id_name;
 555              $serial_manifest = array();
 556              $serial_manifest['manifest'] = (isset($manifest) ? $manifest : '');
 557              $serial_manifest['installdefs'] = (isset($installdefs) ? $installdefs : '');
 558              $serial_manifest['upgrade_manifest'] = (isset($upgrade_manifest) ? $upgrade_manifest : '');
 559              $new_upgrade->manifest        = base64_encode(serialize($serial_manifest));
 560              //$new_upgrade->unique_key    = (isset($manifest['unique_key'])) ? $manifest['unique_key'] : '';

 561              $new_upgrade->save();
 562                      //unlink($file);

 563          }//fi

 564      }
 565          
 566      function getUITextForType( $type ){
 567          if( $type == "full" ){
 568              return( "Full Upgrade" );
 569          }
 570          if( $type == "langpack" ){
 571              return( "Language Pack" );
 572          }
 573          if( $type == "module" ){
 574              return( "Module" );
 575          }
 576          if( $type == "patch" ){
 577              return( "Patch" );
 578          }
 579          if( $type == "theme" ){
 580              return( "Theme" );
 581          }
 582      }
 583      
 584      function getImageForType( $type ){
 585          global $image_path;
 586          $icon = "";
 587          switch( $type ){
 588              case "full":
 589                  $icon = get_image( $image_path . "Upgrade", "" );
 590                  break;
 591              case "langpack":
 592                  $icon = get_image( $image_path . "LanguagePacks", "" );
 593                  break;
 594              case "module":
 595                  $icon = get_image( $image_path . "ModuleLoader", "" );
 596                  break;
 597              case "patch":
 598                  $icon = get_image( $image_path . "PatchUpgrades", "" );
 599                  break;
 600              case "theme":
 601                  $icon = get_image( $image_path . "Themes", "" );
 602                  break;
 603              default:
 604                  break;
 605          }
 606          return( $icon );
 607      }
 608      
 609      function getPackagesInStaging($view = 'module'){
 610          global $sugar_config;
 611          $uh = new UpgradeHistory();
 612          $base_upgrade_dir       = $sugar_config['upload_dir'] . "/upgrades";
 613          $base_tmp_upgrade_dir   = "$base_upgrade_dir/temp";
 614          $upgrade_contents = findAllFiles( "$base_upgrade_dir", array() , false, 'zip');
 615          $upgrades_available = 0;
 616          $packages = array();
 617          $mod_strings = return_module_language('en', "Administration");
 618          foreach($upgrade_contents as $upgrade_content)
 619          {
 620              if(!preg_match("#.*\.zip\$#", $upgrade_content))
 621              {
 622                  continue;
 623              }
 624          
 625              $upgrade_content = clean_path($upgrade_content);
 626              $the_base = basename($upgrade_content);
 627              $the_md5 = md5_file($upgrade_content);
 628              $md5_matches = $uh->findByMd5($the_md5);
 629              $file_install = $upgrade_content;
 630              if(0 == sizeof($md5_matches))
 631              {
 632                  $target_manifest = remove_file_extension( $upgrade_content ) . '-manifest.php';
 633                  require_once($target_manifest);
 634  
 635                  $name = empty($manifest['name']) ? $upgrade_content : $manifest['name'];
 636                  $version = empty($manifest['version']) ? '' : $manifest['version'];
 637                  $published_date = empty($manifest['published_date']) ? '' : $manifest['published_date'];
 638                  $icon = '';
 639                  $description = empty($manifest['description']) ? 'None' : $manifest['description'];
 640                  $uninstallable = empty($manifest['is_uninstallable']) ? 'No' : 'Yes';
 641                  $type = $this->getUITextForType( $manifest['type'] );
 642                  $manifest_type = $manifest['type'];
 643                  $dependencies = array();
 644                  if( isset( $manifest['dependencies']) ){
 645                      $dependencies    = $manifest['dependencies'];
 646                  }
 647  
 648                  //check dependencies first

 649                  if(!empty($dependencies)){
 650                      require_once ('modules/Administration/UpgradeHistory.php');
 651                      $uh = new UpgradeHistory();
 652                      $not_found = $uh->checkDependencies($dependencies);
 653                      if(!empty($not_found) && count($not_found) > 0){
 654                              $file_install = 'errors_'.$mod_strings['ERR_UW_NO_DEPENDENCY']."[".implode(',', $not_found)."]";
 655                      }//fi

 656                  }
 657  
 658                  if($view == 'default' && $manifest_type != 'patch')
 659                  {
 660                      continue;
 661                  }
 662  
 663                  if($view == 'module'
 664                      && $manifest_type != 'module' && $manifest_type != 'theme' && $manifest_type != 'langpack')
 665                  {
 666                      continue;
 667                  }
 668  
 669                  if(empty($manifest['icon'])){
 670                      $icon = $this->getImageForType( $manifest['type'] );
 671                  }else{
 672                      $path_parts = pathinfo( $manifest['icon'] );
 673                      $icon = "<img src=\"" . remove_file_extension( $upgrade_content ) . "-icon." . $path_parts['extension'] . "\">";
 674                  }
 675  
 676                  $upgrades_available++;
 677            
 678                  $upgrade_content = urlencode($upgrade_content);
 679                  $packages[] = array('name' => $name, 'version' => $version, 'published_date' => $published_date, 'description' => $description, 'uninstallable' =>$uninstallable, 'type' => $type, 'file_install' => $file_install, 'file' => $upgrade_content);   
 680              }//fi

 681          }//rof  

 682          return $packages; 
 683      }
 684      
 685      function getLicenseFromFile($file){
 686          global $sugar_config;
 687          $base_upgrade_dir       = $sugar_config['upload_dir'] . "/upgrades";
 688          $base_tmp_upgrade_dir   = "$base_upgrade_dir/temp";   
 689          $license_file = $this->extractFile($file, 'LICENSE.txt', $base_tmp_upgrade_dir); 
 690          if(is_file($license_file)){
 691               $fh = fopen($license_file, 'r');
 692              $contents = fread($fh, filesize($license_file));
 693              fclose($fh);
 694              return $contents;
 695          }else{
 696              return null;
 697          }
 698      }
 699      
 700      /**

 701       * Run the query to obtain the list of installed types as specified by the type param

 702       * 

 703       * @param type    an array of types you would like to search for

 704       *                 type options include (theme, langpack, module, patch)

 705       * 

 706       * @return an array of installed upgrade_history objects

 707       */
 708      function getInstalled($types = array('module')){
 709          $uh = new UpgradeHistory();
 710          $in = "";
 711          for($i = 0; $i < count($types); $i++){
 712              $in .= "'".$types[$i]."'";
 713              if(($i+1) < count($types)){
 714                  $in .= ",";
 715              }
 716          }
 717          $query = "SELECT * FROM ".$uh->table_name."     WHERE type IN (".$in.")";
 718          return $uh->getList($query);
 719      }
 720      
 721      function getinstalledPackages($types = array('module')){
 722          global $sugar_config;
 723          $installeds = $this->getInstalled($types);
 724          $packages = array();
 725          $upgrades_installed = 0;
 726          $uh = new UpgradeHistory();
 727          $base_upgrade_dir       = $sugar_config['upload_dir'] . "/upgrades";
 728          $base_tmp_upgrade_dir   = "$base_upgrade_dir/temp";
 729          foreach($installeds as $installed)
 730          {
 731              $populate = false;
 732              $filename = from_html($installed->filename);
 733              $date_entered = $installed->date_entered;
 734              $type = $installed->type;
 735              $version = $installed->version;
 736              $uninstallable = false;
 737              $link = "";
 738              $description = $installed->description;
 739              $name = $installed->name;
 740              $enabled = true;
 741              $enabled_string = 'ENABLED';
 742              //if the name is empty then we should try to pull from manifest and populate upgrade_history_table

 743              if(empty($name)){
 744                  $populate = true;
 745              }
 746              $upgrades_installed++;
 747              switch($type)
 748              {
 749                  case "theme":
 750                  case "langpack":
 751                  case "module":
 752                  case "patch":
 753                      if($populate){
 754                          $manifest_file = $this->extractManifest($filename, $base_tmp_upgrade_dir);
 755                          require_once($manifest_file);
 756                          $GLOBALS['log']->info("Filling in upgrade_history table");
 757                          $populate = false;
 758                          if( isset( $manifest['name'] ) ){
 759                              $name = $manifest['name'];
 760                              $installed->name = $name;
 761                          }
 762                          if( isset( $manifest['description'] ) ){
 763                              $description = $manifest['description'];
 764                              $installed->description = $description;
 765                          }
 766                          if(isset($installdefs) && isset( $installdefs['id'] ) ){
 767                              $id_name  = $installdefs['id'];
 768                              $installed->id_name = $id_name;
 769                          }
 770                          
 771                          $serial_manifest = array();
 772                          $serial_manifest['manifest'] = (isset($manifest) ? $manifest : '');
 773                          $serial_manifest['installdefs'] = (isset($installdefs) ? $installdefs : '');
 774                          $serial_manifest['upgrade_manifest'] = (isset($upgrade_manifest) ? $upgrade_manifest : '');
 775                          $installed->manifest = base64_encode(serialize($serial_manifest));
 776                          $installed->save();
 777                      }else{
 778                          $serial_manifest = unserialize(base64_decode($installed->manifest));
 779                          $manifest = $serial_manifest['manifest'];
 780                      }
 781                      if(($upgrades_installed==0 || $uh->UninstallAvailable($installeds, $installed))
 782                          && is_file($filename) && !empty($manifest['is_uninstallable']))
 783                      {
 784                          $uninstallable = true;
 785                      }
 786                      $enabled = $installed->enabled;
 787                      if(!$enabled)
 788                          $enabled_string = 'DISABLED';
 789                      $file_uninstall = $filename;
 790                      if(!$uninstallable){
 791                          $file_uninstall = 'UNINSTALLABLE';
 792                          $enabled_string = 'UNINSTALLABLE';
 793                      }
 794                  $packages[] = array('name' => $name, 'version' => $version, 'type' => $type, 'published_date' => $date_entered, 'description' => $description, 'uninstallable' =>$uninstallable, 'file_install' => urlencode( $filename ), 'file' => urlencode( $file_uninstall ), 'enabled' => $enabled_string);   
 795                  break;
 796                  default:
 797                  break;
 798              }
 799              
 800          }//rof

 801          return $packages;
 802      }
 803   }
 804  ?>


Généré le : Tue Sep 11 10:48:47 2007 par Balluche grâce à PHPXref 0.7