Hé, j'voudrais pas faire le fayot, mais y'en a qui trichent, on avait dit
fitcheure frise! :P



---------- Forwarded message ----------
From: <[email protected]>
Date: 2013/10/17
Subject: [Dotclear Tracker] [2428]: 2.6 - Add batch actions on plugins and
themes lists
To: [email protected]


**
 Revision: 2428 (3eff307817bf} Branch: 2.6 Author: Denis Jean-Chirstian **
Date: 2013-10-17 17:41 +0200 Details: Details:
http://dev.dotclear.org/2.0/changeset/3eff307817bf<http://dev.dotclear.org/2.0/changeset/3eff307817bf>
Log
Message

Add batch actions on plugins and themes lists


diffstat:

 inc/admin/lib.moduleslist.php |  237
+++++++++++++++++++++++++++++++++++++++++-
 locales/en/main.po            |   27 ++++
 locales/fr/main.po            |   27 ++++
 3 files changed, 289 insertions(+), 2 deletions(-)

diffs (truncated from 384 to 300 lines):

diff -r 6f339b5f4bd0 -r 3eff307817bf inc/admin/lib.moduleslist.php
--- a/inc/admin/lib.moduleslist.php     Thu Oct 17 17:05:45 2013 +0200
+++ b/inc/admin/lib.moduleslist.php     Thu Oct 17 17:41:32 2013 +0200
@@ -731,6 +731,21 @@
                        '<p class="message">'.__('No plugins matched your
search.').'</p>';
                }

+               if ($count > 1 && !empty($actions) &&
$this->core->auth->isSuperAdmin()) {
+                       $buttons = $this->getGlobalActions($actions);
+
+                       echo
+                       '<form action="'.$this->getURL().'" method="post"
class="global-actions-buttons">'.
+                       '<div>'.
+                       $this->core->formNonce().
+                       form::hidden(array('modules'), '1').
+
+                       implode(' ', $buttons).
+
+                       '</div>'.
+                       '</form>';
+               }
+
                return $this;
        }

@@ -794,6 +809,53 @@
                        }
                }

+               return $submits;
+       }
+
+       /**
+        * Get global action buttons to add to modules list.
+        *
+        * @param       array   $actions        Actions keys
+        * @return      Array of actions buttons
+        */
+       protected function getGlobalActions($actions)
+       {
+               $submits = array();
+
+               # Use loop to keep requested order
+               foreach($actions as $action) {
+                       switch($action) {
+
+                               # Deactivate
+                               case 'activate': if ($this->path_writable) {
+                                       $submits[] =
+                                       '<input type="submit"
name="activate" value="'.__('Activate all plugins from this list').'" />';
+                               } break;
+
+                               # Activate
+                               case 'deactivate': if
($this->path_writable) {
+                                       $submits[] =
+                                       '<input type="submit"
name="deactivate" value="'.__('Deactivate all plugins from this list').'"
class="reset" />';
+                               } break;
+
+                               # Update (from store)
+                               case 'update': if ($this->path_writable) {
+                                       $submits[] =
+                                       '<input type="submit" name="update"
value="'.__('Update all plugins from this list').'" />';
+                               } break;
+
+                               # Behavior
+                               case 'behavior':
+
+                                       # --BEHAVIOR--
adminModulesListGetGlobalActions
+                                       $tmp =
$this->core->callBehavior('adminModulesListGetGlobalActions', $this);
+
+                                       if (!empty($tmp)) {
+                                               $submits[] = $tmp;
+                                       }
+                               break;
+                       }
+               }

                return $submits;
        }
@@ -812,7 +874,7 @@
                        return null;
                }

-               # List actions
+               # Actions per module
                if (!empty($_POST['module'])) {

                        $id = $_POST['module'];
@@ -892,7 +954,6 @@
                                dcPage::addSuccessNotice(__('Plugin has
been successfully deleted.'));
                                http::redirect($this->getURL());
                        }
-
                        elseif (!empty($_POST['install'])) {

                                $updated = $this->store->get();
@@ -964,6 +1025,98 @@

                        }
                }
+               # Global actions
+               elseif (!empty($_POST['modules'])) {
+
+                       if (!empty($_POST['activate'])) {
+
+                               $modules =
$this->modules->getDisabledModules();
+                               if (empty($modules)) {
+                                       throw new Exception(__('No such
plugin.'));
+                               }
+
+                               foreach($modules as $id => $module) {
+
+                                       # --BEHAVIOR-- moduleBeforeActivate
+
$this->core->callBehavior('pluginBeforeActivate', $id);
+
+                                       $this->modules->activateModule($id);
+
+                                       # --BEHAVIOR-- moduleAfterActivate
+
$this->core->callBehavior('pluginAfterActivate', $id);
+
+                               }
+
+                               dcPage::addSuccessNotice(__('Plugins have
been successfully activated.'));
+                               http::redirect($this->getURL());
+                       }
+
+                       elseif (!empty($_POST['deactivate'])) {
+
+                               $modules = $this->modules->getModules();
+                               if (empty($modules)) {
+                                       throw new Exception(__('No such
plugin.'));
+                               }
+
+                               $failed = false;
+                               foreach($modules as $id => $module) {
+                                       $module[$id] = $id;
+
+                                       if (!$module['root_writable']) {
+                                               $failed = true;
+                                               continue;
+                                       }
+
+                                       # --BEHAVIOR--
moduleBeforeDeactivate
+
$this->core->callBehavior('pluginBeforeDeactivate', $module);
+
+
$this->modules->deactivateModule($id);
+
+                                       # --BEHAVIOR-- moduleAfterDeactivate
+
$this->core->callBehavior('pluginAfterDeactivate', $module);
+                               }
+
+                               if ($failed) {
+                                       dcPage::addWarningNotice(__('Some
plugins have not been deactivated.'));
+                               }
+                               else {
+
dcPage::addSuccessNotice(__('Plugins have been successfully deactivated.'));
+                               }
+                               http::redirect($this->getURL());
+                       }
+
+                       elseif (!empty($_POST['update'])) {
+
+                               $updated = $this->store->get(true);
+                               if (empty($updated)) {
+                                       throw new Exception(__('No such
plugin.'));
+                               }
+
+                               foreach($updated as $module) {
+
+                                       if (!self::$allow_multi_install) {
+                                               $dest =
$module['root'].'/../'.basename($module['file']);
+                                       }
+                                       else {
+                                               $dest =
$this->getPath().'/'.basename($module['file']);
+                                               if ($module['root'] !=
$dest) {
+
@file_put_contents($module['root'].'/_disabled', '');
+                                               }
+                                       }
+
+                                       # --BEHAVIOR-- moduleBeforeUpdate
+
$this->core->callBehavior('pluginBeforeUpdate', $module);
+
+
$this->store->process($module['file'], $dest);
+
+                                       # --BEHAVIOR-- moduleAfterUpdate
+
$this->core->callBehavior('pluginAfterUpdate', $module);
+                               }
+
+                               dcPage::addSuccessNotice(__('Plugins have
been successfully updated.'));
+                               http::redirect($this->getURL().'#plugins');
+                       }
+               }
                # Manual actions
                elseif (!empty($_POST['upload_pkg']) &&
!empty($_FILES['pkg_file'])
                        || !empty($_POST['fetch_pkg']) &&
!empty($_POST['pkg_url']))
@@ -1377,6 +1530,21 @@
                        echo
                        '<p class="message">'.__('No themes matched your
search.').'</p>';
                }
+
+               if ($count > 1 && !empty($actions) &&
$this->core->auth->isSuperAdmin()) {
+                       $buttons = $this->getGlobalActions($actions);
+
+                       echo
+                       '<form action="'.$this->getURL().'" method="post"
class="global-actions-buttons">'.
+                       '<div>'.
+                       $this->core->formNonce().
+                       form::hidden(array('modules'), '1').
+
+                       implode(' ', $buttons).
+
+                       '</div>'.
+                       '</form>';
+               }
        }

        protected function getActions($id, $module, $actions)
@@ -1399,6 +1567,36 @@
                );
        }

+       protected function getGlobalActions($actions)
+       {
+               $submits = array();
+
+               foreach($actions as $action) {
+                       switch($action) {
+
+
+                               # Update (from store)
+                               case 'update': if ($this->path_writable) {
+                                       $submits[] =
+                                       '<input type="submit" name="update"
value="'.__('Update all themes from this list').'" />';
+                               } break;
+
+                               # Behavior
+                               case 'behavior':
+
+                                       # --BEHAVIOR--
adminModulesListGetGlobalActions
+                                       $tmp =
$this->core->callBehavior('adminModulesListGetGlobalActions', $this);
+
+                                       if (!empty($tmp)) {
+                                               $submits[] = $tmp;
+                                       }
+                               break;
+                       }
+               }
+
+               return $submits;
+       }
+
        public function doActions()
        {
                if (empty($_POST) || !empty($_REQUEST['conf'])
@@ -1571,6 +1769,41 @@

                        }
                }
+               # Global actions
+               elseif (!empty($_POST['modules'])) {
+
+                       if (!empty($_POST['update'])) {
+
+                               $updated = $this->store->get(true);
+                               if (empty($updated)) {
+                                       throw new Exception(__('No such
theme.'));
+                               }
+
+                               foreach($updated as $module) {
+
+                                       if (!self::$allow_multi_install) {
+                                               $dest =
$module['root'].'/../'.basename($module['file']);
+                                       }
+                                       else {
+                                               $dest =
$this->getPath().'/'.basename($module['file']);
+                                               if ($module['root'] !=
$dest) {
+
@file_put_contents($module['root'].'/_disabled', '');
+                                               }
+                                       }
+
+                                       # --BEHAVIOR-- moduleBeforeUpdate
+
$this->core->callBehavior('themesBeforeUpdate', $module);
+
+
$this->store->process($module['file'], $dest);
+
+                                       # --BEHAVIOR-- moduleAfterUpdate
+
$this->core->callBehavior('themesAfterUpdate', $module);
+                               }
+
+                               dcPage::addSuccessNotice(__('Themes have
been successfully updated.'));
+                               http::redirect($this->getURL().'#themes');
+                       }
+               }
                # Manual actions
                elseif (!empty($_POST['upload_pkg']) &&
!empty($_FILES['pkg_file'])
                        || !empty($_POST['fetch_pkg']) &&
!empty($_POST['pkg_url']))
diff -r 6f339b5f4bd0 -r 3eff307817bf locales/en/main.po
--- a/locales/en/main.po        Thu Oct 17 17:05:45 2013 +0200
+++ b/locales/en/main.po        Thu Oct 17 17:41:32 2013 +0200
@@ -2863,6 +2863,27 @@
--
Tracker mailing list - [email protected] -
http://ml.dotclear.net/listinfo/tracker
-- 
Dev mailing list - [email protected] - http://ml.dotclear.org/listinfo/dev

Répondre à