Dotclear

Changeset 3007:f9d013776723 for inc


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.

Location:
inc
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • inc/admin/lib.moduleslist.php

    r2997 r3007  
    672672                    echo 
    673673                    '<td class="module-desc maximal">'.html::escapeHTML(__($module['desc'])); 
    674                     if (in_array('deps', $cols)) { 
    675  
    676                          if (isset($module['disable_also'])) { 
    677                               echo 
    678                               '<br/><span class="info">'.__('Disabling or removing this plugin will also disable the following plugins: '). 
    679                               join(',',$module['disable_also']).'</span>'; 
     674                    if (isset($module['cannot_disable']) && $module['enabled']) { 
     675                         echo 
     676                         '<br/><span class="info">'. 
     677                         sprintf(__('This module cannot be disabled nor deleted, since the following modules are also enabled : %s'), 
     678                                   join(',',$module['cannot_disable'])). 
     679                         '</span>'; 
     680                    } 
     681                    if (isset($module['cannot_enable']) && !$module['enabled']) { 
     682                         echo 
     683                         '<br/><span class="info">'. 
     684                         __('This module cannot be enabled, because of the following reasons :'). 
     685                         '<ul>'; 
     686                         foreach ($module['cannot_enable'] as $m=>$reason) { 
     687                              echo '<li>'.$reason.'</li>'; 
    680688                         } 
     689                         echo '</ul>'. 
     690                         '</span>'; 
    681691                    } 
    682692                    echo '</td>'; 
     
    815825 
    816826                    # Deactivate 
    817                     case 'activate': if ($this->core->auth->isSuperAdmin() && $module['root_writable']) { 
     827                    case 'activate': if ($this->core->auth->isSuperAdmin() && $module['root_writable'] && !isset($module['cannot_enable'])) { 
    818828                         $submits[] = 
    819829                         '<input type="submit" name="activate['.html::escapeHTML($id).']" value="'.__('Activate').'" />'; 
     
    821831 
    822832                    # Activate 
    823                     case 'deactivate': if ($this->core->auth->isSuperAdmin() && $module['root_writable']) { 
     833                    case 'deactivate': if ($this->core->auth->isSuperAdmin() && $module['root_writable'] && !isset($module['cannot_disable'])) { 
    824834                         $submits[] = 
    825835                         '<input type="submit" name="deactivate['.html::escapeHTML($id).']" value="'.__('Deactivate').'" class="reset" />'; 
     
    827837 
    828838                    # Delete 
    829                     case 'delete': if ($this->core->auth->isSuperAdmin() && $this->isDeletablePath($module['root'])) { 
     839                    case 'delete': if ($this->core->auth->isSuperAdmin() && $this->isDeletablePath($module['root'])&& !isset($module['cannot_disable'])) { 
    830840                         $dev = !preg_match('!^'.$this->path_pattern.'!', $module['root']) && defined('DC_DEV') && DC_DEV ? ' debug' : ''; 
    831841                         $submits[] = 
  • 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