[ Index ]
 

Code source de CMS made simple 1.0.5

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

title

Body

[fermer]

/modules/ModuleManager/ -> action.upgrademodule.php (source)

   1  <?php
   2  {
   3    // upgrade a module
   4    global $gCms;
   5    
   6    if( !isset( $params['name'] ) )
   7      {
   8        $this->_DisplayErrorPage( $id, $params, $returnid,
   9                  $this->Lang('error_insufficientparams'));
  10        return;
  11      }
  12    $name = $params['name'];
  13    
  14    if( !isset( $params['version'] ) )
  15      {
  16        $this->_DisplayErrorPage( $id, $params, $returnid,
  17                  $this->Lang('error_insufficientparams'));
  18        return;
  19      }
  20    $version = $params['version'];
  21    
  22    $url = $this->GetPreference('module_repository');
  23    if( $url == '' )
  24      {
  25        $this->_DisplayErrorPage( $id, $params, $returnid,
  26                  $this->Lang('error_norepositoryurl'));
  27        return;
  28      }
  29    
  30    $xmlfile = $name.'-'.$version.'.xml';
  31  
  32    $nusoap =& $this->GetModuleInstance('nuSOAP');
  33    $nusoap->Load();
  34    $nu_soapclient =& new nu_soapclient($url,false,false,false,false,false,0,90);
  35    if( $err = $nu_soapclient->GetError() )
  36      {
  37        $this->_DisplayErrorPage( $id, $params, $returnid,
  38                  'SOAP Error: '.$err);
  39        return;
  40      }
  41    
  42    // get the xml file from soap
  43    $xml = $nu_soapclient->call('ModuleRepository.soap_modulexml',array('name' => $xmlfile ));
  44    if( $err = $nu_soapclient->GetError() )
  45      {
  46        $this->_DisplayErrorPage( $id, $params, $returnid,
  47                  'SOAP Error: '.$err);
  48        return;
  49      }
  50    
  51    // get the md5sum from soap
  52    $svrmd5 = $nu_soapclient->call('ModuleRepository.soap_modulemd5sum',array('name' => $xmlfile));
  53    if( $err = $nu_soapclient->GetError() )
  54      {
  55        $this->_DisplayErrorPage( $id, $params, $returnid,
  56                  'SOAP Error: '.$err);
  57        return;
  58      }
  59    
  60    // calculate our own md5sum
  61    // and compare
  62    $clientmd5 = md5( $xml );
  63    
  64    if( $clientmd5 != $svrmd5 )
  65      {
  66        $this->_DisplayErrorPage( $id, $params, $returnid,
  67                  $this->Lang('error_checksum'));
  68        return;
  69      }
  70    
  71    // woohoo, we're ready to rock and roll now
  72    // just gotta expand the module
  73    $modoperations = $gCms->GetModuleOperations();
  74    if( !$modoperations->ExpandXMLPackage( $xml, 1 ) )
  75      {
  76        $this->_DisplayErrorPage( $id, $params, $returnid,
  77                  $modoperations->GetLastError());
  78        return;
  79      }
  80  
  81    // we get the version number from the database
  82    // just incase the module is inactive or something and therefore
  83    // not loaded.
  84    $query = "SELECT * FROM ".cms_db_prefix()."modules WHERE module_name = ?";
  85    $dbresult = $db->Execute( $query, array( $name ) );
  86    $row = $dbresult->FetchRow();
  87    $oldversion = $row['version'];
  88  
  89    if( !isset( $gCms->modules[$name] ) )
  90      {
  91        echo "DEBUG: module not loaded<br/>";
  92        if( !$modoperations->LoadNewModule( $name ) )
  93      {
  94        // error
  95      }
  96      }
  97  
  98    if( !$modoperations->UpgradeModule( $name, $oldversion, $version ) )
  99      {
 100        // error
 101      }
 102  
 103    // and redirect back to the start
 104    $this->Redirect( $id, 'defaultadmin', $returnid );
 105  }
 106  ?>


Généré le : Tue Apr 3 18:50:37 2007 par Balluche grâce à PHPXref 0.7