Changeset 29779


Ignore:
Timestamp:
Sep 25, 2014, 11:25:24 AM (10 years ago)
Author:
mistic100
Message:

final fix for plugins update ?

  • plugins.version is not updated in "activate" action
  • plugins.version is updated in "update" action and "load_plugin()" function (not only for plugins using maintain.class.php)

cases covered:

  • autoupdate while active or inactive
  • FTP update while active or inactive
Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/admin/include/plugins.class.php

    r29778 r29779  
    153153      case 'update':
    154154        $previous_version = $this->fs_plugins[$plugin_id]['version'];
    155         $upgrade_status = $this->extract_plugin_files('upgrade', $options['revision'], $plugin_id);
    156 
    157         if ($upgrade_status === 'ok')
     155        $errors[0] = $this->extract_plugin_files('upgrade', $options['revision'], $plugin_id);
     156
     157        if ($errors[0] === 'ok')
    158158        {
    159159          $this->get_fs_plugin($plugin_id); // refresh plugins list
     160          $new_version = $this->fs_plugins[$plugin_id]['version'];
    160161
    161162          $plugin_maintain = self::build_maintain_class($plugin_id);
    162           $plugin_maintain->update($previous_version, $this->fs_plugins[$plugin_id]['version']);
    163         }
    164 
    165         return $upgrade_status;
     163          $plugin_maintain->update($previous_version, $new_version, $errors);
     164
     165          if ($new_version != 'auto')
     166          {
     167            $query = '
     168UPDATE '. PLUGINS_TABLE .'
     169  SET version=\''. $new_version .'\'
     170  WHERE id=\''. $plugin_id .'\'
     171;';
     172            pwg_query($query);
     173          }
     174        }
     175
    166176        break;
    167177
     
    187197          $query = '
    188198UPDATE '. PLUGINS_TABLE .'
    189   SET state=\'active\',
    190     version=\''. $this->fs_plugins[$plugin_id]['version'] .'\'
     199  SET state=\'active\'
    191200  WHERE id=\''. $plugin_id .'\'
    192201;';
  • trunk/include/functions_plugins.inc.php

    r29316 r29779  
    377377function autoupdate_plugin(&$plugin)
    378378{
    379   $maintain_file = PHPWG_PLUGINS_PATH.$plugin['id'].'/maintain.class.php';
    380 
    381   // autoupdate is applicable only to plugins with 2.7 architecture
    382   if (file_exists($maintain_file))
    383   {
    384     // try to find the filesystem version in lines 2 to 10 of main.inc.php
    385     $fh = fopen(PHPWG_PLUGINS_PATH.$plugin['id'].'/main.inc.php', 'r');
    386     $fs_version = null;
    387     $i = -1;
    388 
    389     while (($line = fgets($fh))!==false && $fs_version==null && $i<10)
    390     {
    391       $i++;
    392       if ($i < 2) continue; // first lines are typically "<?php" and "/*"
    393 
    394       if (preg_match('/Version:\\s*([\\w.-]+)/', $line, $matches))
    395       {
    396         $fs_version = $matches[1];
    397       }
    398     }
    399 
    400     fclose($fh);
    401 
    402     if ($fs_version != null)
    403     {
    404       global $pwg_loaded_plugins, $page;
    405 
    406       // if version is auto (dev) or superior
    407       if (
    408           $fs_version == 'auto' or $plugin['version'] == 'auto'
    409           or safe_version_compare($plugin['version'], $fs_version, '<')
    410         )
    411       {
    412         // call update method
    413         include_once($maintain_file);
    414 
    415         $classname = $plugin['id'].'_maintain';
    416         $plugin_maintain = new $classname($plugin['id']);
    417         $plugin_maintain->update($plugin['version'], $fs_version, $page['errors']);
    418 
    419         $plugin['version'] = $fs_version;
    420 
    421         // update database (only on production)
    422         if ($plugin['version'] != 'auto')
    423         {
    424           $query = '
     379  // try to find the filesystem version in lines 2 to 10 of main.inc.php
     380  $fh = fopen(PHPWG_PLUGINS_PATH.$plugin['id'].'/main.inc.php', 'r');
     381  $fs_version = null;
     382  $i = -1;
     383
     384  while (($line = fgets($fh))!==false && $fs_version==null && $i<10)
     385  {
     386    $i++;
     387    if ($i < 2) continue; // first lines are typically "<?php" and "/*"
     388
     389    if (preg_match('/Version:\\s*([\\w.-]+)/', $line, $matches))
     390    {
     391      $fs_version = $matches[1];
     392    }
     393  }
     394
     395  fclose($fh);
     396
     397  // if version is auto (dev) or superior
     398  if ($fs_version != null && (
     399        $fs_version == 'auto' || $plugin['version'] == 'auto' ||
     400        safe_version_compare($plugin['version'], $fs_version, '<')
     401      )
     402  ) {
     403    $plugin['version'] = $fs_version;
     404
     405    $maintain_file = PHPWG_PLUGINS_PATH.$plugin['id'].'/maintain.class.php';
     406
     407    // autoupdate is applicable only to plugins with 2.7 architecture
     408    if (file_exists($maintain_file))
     409    {
     410      global $page;
     411
     412      // call update method
     413      include_once($maintain_file);
     414
     415      $classname = $plugin['id'].'_maintain';
     416      $plugin_maintain = new $classname($plugin['id']);
     417      $plugin_maintain->update($plugin['version'], $fs_version, $page['errors']);
     418    }
     419
     420    // update database (only on production)
     421    if ($plugin['version'] != 'auto')
     422    {
     423      $query = '
    425424UPDATE '. PLUGINS_TABLE .'
    426425  SET version = "'. $plugin['version'] .'"
    427426  WHERE id = "'. $plugin['id'] .'"
    428427;';
    429           pwg_query($query);
    430         }
    431       }
     428      pwg_query($query);
    432429    }
    433430  }
  • trunk/include/ws_functions/pwg.extensions.php

    r29773 r29779  
    189189    }
    190190
    191     $upgrade_status = $extension->perform_action('update', $extension_id, array('revision'=>$revision));
     191    list($upgrade_status) = $extension->perform_action('update', $extension_id, array('revision'=>$revision));
    192192    $extension_name = $extension->fs_plugins[$extension_id]['name'];
    193193
Note: See TracChangeset for help on using the changeset viewer.