Dotclear


Ignore:
Timestamp:
06/05/15 15:56:08 (10 years ago)
Author:
Dsls
Branch:
default
Message:

Update dependencies management, add notices and prevent enabling/disabling modules when dependencies are unmet.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • inc/core/class.dc.modules.php

    r2997 r3007  
    5252     } 
    5353 
    54  
     54     /** 
     55      * Checks all modules dependencies 
     56      *   Fills in the following information in module : 
     57      *     * cannot_enable : list reasons why module cannot be enabled. Not set if module can be enabled 
     58      *     * cannot_disable : list reasons why module cannot be disabled. Not set if module can be disabled 
     59      *     * implies : reverse dependencies 
     60      * @return array list of enabled modules with unmet dependencies, and that must be disabled. 
     61      */ 
    5562     public function checkDependencies() { 
    5663          $to_disable = array(); 
    5764          foreach ($this->all_modules as $k => &$m) { 
    5865               if (isset($m['requires'])) { 
     66                    $missing = array(); 
    5967                    foreach ($m['requires'] as &$dep) { 
    60                          $missing = array(); 
    6168                         if (!is_array($dep)) { 
    6269                              $dep = array($dep); 
    6370                         } 
     71                         // grab missing dependencies 
    6472                         if (!isset($this->all_modules[$dep[0]])) { 
    6573                              // module not present 
    66                               $missing[$dep[0]] = true; 
    67                          } elseif (count($dep)>1 && version_compare($m['version'],$dep[1],'<')) { 
     74                              $missing[$dep[0]] = sprintf(__("Requires module %s which is not installed"), $dep[0]); 
     75                         } elseif ((count($dep)>1) && version_compare($this->all_modules[$dep[0]]['version'],$dep[1])==-1) { 
     76                              echo "bla:".version_compare($this->all_modules[$dep[0]]['version'],$dep[1],'<'); 
    6877                              // module present, but version missing 
    69                               $missing[$dep[0]] = $dep[1]; 
     78                              $missing[$dep[0]] = sprintf(__("Requires module %s version %s, but version %s is installed"), $dep[0],$dep[1],$m['version']); 
     79                         } elseif (!$this->all_modules[$dep[0]]['enabled']) { 
     80                              // module disabled 
     81                              $missing[$dep[0]] = sprintf(__("Requires module %s which is disabled"), $dep[0]); 
    7082                         } 
    71                          if (count($missing)) { 
    72                               $m['errors']=$missing; 
    73                               $to_disable[]=$k; 
    74                          } else { 
    75                               $this->all_modules[$dep[0]]['disable_also'][]=$k; 
    76                               $m['require_enable'][]=$dep[0]; 
    77                               if (!$this->all_modules[$dep[0]]['enabled']) { 
    78                                    $to_disable[]=$k; 
    79                               } 
     83                         $this->all_modules[$dep[0]]['implies'][]=$k; 
     84                    } 
     85                    if (count($missing)) { 
     86                         $m['cannot_enable']=$missing; 
     87                         if ($m['enabled']) { 
     88                              $to_disable[]=array('name' => $k,'reason'=> $missing); 
    8089                         } 
    8190                    } 
    8291               } 
    8392          } 
     93          // Check modules that cannot be disabled 
     94          foreach ($this->modules as $k => &$m) { 
     95               if (isset($m['implies']) && $m['enabled']) { 
     96                    foreach ($m['implies'] as $im) { 
     97                         if (isset($this->all_modules[$im]) && $this->all_modules[$im]['enabled']) { 
     98                              $m['cannot_disable'][]=$im; 
     99                         } 
     100                    } 
     101               } 
     102          } 
     103          return $to_disable; 
    84104     } 
    85105 
Note: See TracChangeset for help on using the changeset viewer.

Sites map