Ignore:
Timestamp:
Jan 28, 2011, 5:10:45 PM (13 years ago)
Author:
grum
Message:

release 3.0.0
fix bug:1716, bug:2128, bug:1296, bug:2052, bug:1910, bug:1723, bug:1709, bug:1680, bug:1477, bug:2129
rewrite plugin core, implement ajax interface, optimize JS

File:
1 edited

Legend:

Unmodified
Added
Removed
  • extensions/AMenuManager/amm_install.class.inc.php

    r5545 r8962  
    33  Plugin     : Advanced Menu Manager
    44  Author     : Grum
    5     email    : grum@grum.dnsalias.com
     5    email    : grum@piwigo.org
    66    website  : http://photos.grum.fr
    77    PWG user : http://forum.phpwebgallery.net/profile.php?id=3706
     
    2121  class AMM_install extends AMM_root
    2222  {
    23     private $tablesManager;
    24     private $exportfile;
    25 
    26     public function AMM_install($prefixeTable, $filelocation)
     23    private $tablef;
     24
     25    public function __construct($prefixeTable, $filelocation)
    2726    {
    2827      parent::__construct($prefixeTable, $filelocation);
    29       $this->tablesManager= new GPCTables($this->tables);
    30       $this->exportfile=dirname($this->getFileLocation()).'/'.$this->getPluginNameFiles().'.sql';
    31     }
    32 
    33     /*
    34         function for installation process
    35         return true if install process is ok, otherwise false
    36     */
     28      $this->tablef= new GPCTables($this->tables);
     29    }
     30
     31    public function __destruct()
     32    {
     33      unset($this->tablesManager);
     34      unset($this->tablef);
     35      parent::__destruct();
     36    }
     37
     38
     39    /**
     40     * function for installation process
     41     *
     42     * @return Bool : true if install process is ok, otherwise false
     43     */
    3744    public function install()
    3845    {
     
    4047      $this->loadConfig();
    4148      $this->config['installed']=AMM_VERSION2;
     49      $this->config['newInstall']='y';
    4250      $this->saveConfig();
    4351
     
    5159  `position` int(11) NOT NULL default '0',
    5260  `visible` char(1) NOT NULL default 'y',
     61  `accessUsers` varchar(1024) NOT NULL,
     62  `accessGroups` varchar(1024) NOT NULL,
    5363  PRIMARY KEY  (`id`),
    5464  KEY `order_key` (`position`)
     
    5666
    5767"CREATE TABLE  `".$this->tables['personalised']."` (
    58   `id` int(11) NOT NULL default '0',
    59   `lang` varchar(5) NOT NULL default '',
    60   `title` varchar(255) NOT NULL default '',
    61   `content` text NOT NULL,
     68  `id` int(11) NOT NULL auto_increment,
    6269  `visible` char(1) NOT NULL default 'y',
    6370  `nfo` varchar(255) NOT NULL default '',
    64   PRIMARY KEY  (`id`,`lang`)
     71  PRIMARY KEY  (`id`)
     72)",
     73
     74"CREATE TABLE `".$this->tables['personalised_langs']."` (
     75  `id` INTEGER UNSIGNED NOT NULL DEFAULT 0,
     76  `lang` CHAR(5)  NOT NULL default '*',
     77  `title` VARCHAR(255)  NOT NULL default '',
     78  `content` TEXT  NOT NULL,
     79  PRIMARY KEY (`id`, `lang`)
     80)",
     81
     82"CREATE TABLE `".$this->tables['blocks']."` (
     83  `id` VARCHAR(40)  NOT NULL,
     84  `order` INTEGER UNSIGNED NOT NULL,
     85  `users` VARCHAR(1024)  NOT NULL,
     86  `groups` VARCHAR(1024)  NOT NULL,
     87  PRIMARY KEY (`id`),
     88  INDEX `byOrder`(`order`)
    6589)"
     90
    6691);
    6792      //$table_def array
    6893      $tables_def = create_table_add_character_set($tables_def);
    69       $result=$this->tablesManager->create($tables_def);
     94      $result=$this->tablef->create($tables_def);
     95      unset($tables_def);
     96
     97      GPCCore::register($this->getPluginName(), AMM_VERSION, AMM_GPC_NEEDED);
     98
    7099      return($result);
    71100    }
    72101
    73102
    74     /*
    75        function for uninstall process
    76     */
     103    /**
     104     * function for uninstall process
     105     */
    77106    public function uninstall()
    78107    {
    79       $this->tablesManager->export($this->exportfile);
    80108      $this->deleteConfig();
    81       $this->tablesManager->drop();
     109      $this->tablef->drop();
     110      GPCCore::unregister($this->getPluginName());
    82111    }
    83112
     
    91120      $this->udpateTablesDef();
    92121
     122      $this->config['newInstall']='n';
    93123      $this->config['installed']=AMM_VERSION2; //update the installed release number
    94124      $this->saveConfig();
     125
     126      GPCCore::register($this->getPluginName(), AMM_VERSION, AMM_GPC_NEEDED);
    95127    }
    96128
    97129    public function deactivate()
    98130    {
     131      $this->initConfig();
     132      $this->loadConfig();
     133      $this->restoreMenuConfig();
    99134    }
    100135
     
    106141    protected function udpateTablesDef()
    107142    {
     143      global $conf;
     144
    108145      /* AMM release earlier than the 2.1.3 uses two parameters to manage the display
    109146       * of the menu items ("amm_sections_modspecials" and "amm_sections_modmenu")
    110147       *
    111        * These two parameters are replaced by a single parameter "amm_sections_items"
     148       * These two parameters are replaced by a single parameter "amm_blocks_items"
    112149       *
    113150       * This function aim to import the old conf into the new conf property
     
    117154        foreach($this->config['amm_sections_modspecials'] as $key=>$val)
    118155        {
    119           $this->config['amm_sections_items'][$key]['visibility']=($val=="y")?"guest,generic,normal,admin/":"admin/";
     156          $this->config['amm_blocks_items'][$key]['visibility']=($val=="y")?"guest,generic,normal,admin/":"admin/";
    120157        }
    121158        unset($this->config['amm_sections_modspecials']);
     
    126163        foreach($this->config['amm_sections_modmenu'] as $key=>$val)
    127164        {
    128           $this->config['amm_sections_items'][$key]['visibility']=($val=="y")?"guest,generic,normal,admin/":"admin/";
     165          $this->config['amm_blocks_items'][$key]['visibility']=($val=="y")?"guest,generic,normal,admin/":"admin/";
    129166        }
    130167        unset($this->config['amm_sections_modmenu']);
     
    140177      }
    141178
    142       if($this->config['installed']<="02.01.06")
    143       {
    144         /*
    145          * 2.2.0 updates
    146          *
    147          * - update fields length for table 'personalised'
    148          * - update config for menu translation
    149          */
    150         $sql="ALTER TABLE `".$this->tables['personalised']."`
    151               MODIFY COLUMN `title` VARCHAR(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
    152               MODIFY COLUMN `nfo` VARCHAR(255)  CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL;";
    153         pwg_query($sql);
    154 
    155         foreach($this->config['amm_sections_items'] as $key => $val)
     179      switch($this->config['installed'])
     180      {
     181        case '02.01.06':
     182          $this->config['newInstall']='n';
     183          $this->updateFrom_020106();
     184        case '02.02.00':
     185          $this->config['newInstall']='n';
     186          $this->updateFrom_020200();
     187        default:
     188          /*
     189           * default is applied for fresh install
     190           */
     191
     192          if($this->config['installed']<='02.02.02' or
     193             $this->config['newInstall']=='y')
     194          {
     195            /*
     196             * if    new install
     197             *    or plugin updated from a release <= 2.2.0
     198             *    or plugin
     199             *
     200             * update AMM menu from piwigo's menu
     201             */
     202            $this->backupMenuConfig(true);
     203          }
     204          else
     205          {
     206            /*
     207             * plugin actived without being installed or updated, only backup
     208             * the piwigo's menu
     209             */
     210            $this->backupMenuConfig(false);
     211          }
     212          break;
     213      }
     214
     215    }
     216
     217    /**
     218     * update the database from the release 2.1.6
     219     *
     220     * - update config for menu translation
     221     * - update fields length for table 'personalised'
     222     */
     223    private function updateFrom_020106()
     224    {
     225      $sql="ALTER TABLE `".$this->tables['personalised']."`
     226            MODIFY COLUMN `id` INTEGER  NOT NULL AUTO_INCREMENT,
     227            MODIFY COLUMN `title` VARCHAR(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
     228            MODIFY COLUMN `nfo` VARCHAR(255)  CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL;";
     229      pwg_query($sql);
     230
     231      foreach($this->config['amm_blocks_items'] as $key => $val)
     232      {
     233        $this->config['amm_blocks_items'][$key]['translation'] = $this->defaultMenus[$key]['translation'];
     234      }
     235    }
     236
     237
     238
     239    /**
     240     * update the database from the release 2.2.0
     241     *
     242     * - create 'personalised_lang' table ; filled from the 'personalised' table
     243     *   values
     244     * - modify 'personalised' table structure (remove lang attributes)
     245     * - modify 'urls' table structure (add users&group access)
     246     * - update 'urls' table values (default values for users access)
     247     * - update config (parameter 'amm_sections_items' is renamed into 'amm_blocks_items')
     248     */
     249    private function updateFrom_020200()
     250    {
     251      $tables_def=array(
     252"CREATE TABLE `".$this->tables['personalised_langs']."` (
     253  `id` INTEGER UNSIGNED NOT NULL DEFAULT 0,
     254  `lang` CHAR(5)  NOT NULL default '*',
     255  `title` VARCHAR(255)  NOT NULL default '',
     256  `content` TEXT  NOT NULL,
     257  PRIMARY KEY (`id`, `lang`)
     258)",
     259
     260"CREATE TABLE `".$this->tables['blocks']."` (
     261  `id` VARCHAR(40)  NOT NULL,
     262  `order` INTEGER UNSIGNED NOT NULL,
     263  `users` VARCHAR(1024)  NOT NULL,
     264  `groups` VARCHAR(1024)  NOT NULL,
     265  PRIMARY KEY (`id`),
     266  INDEX `byOrder`(`order`)
     267)"
     268      );
     269
     270      $tables_def = create_table_add_character_set($tables_def);
     271      $result=$this->tablef->create($tables_def);
     272
     273      $sql="INSERT INTO `".$this->tables['personalised_langs']."`
     274              SELECT pap.id, pap.lang, pap.title, pap.content
     275              FROM `".$this->tables['personalised']."` pap
     276              WHERE pap.title!='' OR pap.content!='';";
     277      pwg_query($sql);
     278
     279      $sql="ALTER TABLE `".$this->tables['personalised']."` DROP COLUMN `lang`,
     280             DROP COLUMN `title`,
     281             DROP COLUMN `content`;";
     282      pwg_query($sql);
     283
     284      $sql="ALTER TABLE `".$this->tables['urls']."`
     285            ADD COLUMN `accessUsers` VARCHAR(1024)  NOT NULL AFTER `visible`,
     286            ADD COLUMN `accessGroups` VARCHAR(1024)  NOT NULL AFTER `accessUser`;";
     287      pwg_query($sql);
     288
     289
     290      $users=new GPCUsers();
     291      $sql="UPDATE `".$this->tables['urls']."`
     292            SET accessUsers='".pwg_db_real_escape_string(implode(',', $users->getList()))."';";
     293      pwg_query($sql);
     294
     295      if(isset($this->config['amm_sections_items']))
     296      {
     297        $this->config['amm_blocks_items']=$this->config['amm_sections_items'];
     298        unset($this->config['amm_sections_items']);
     299      }
     300    }
     301
     302    /**
     303     * report hidden menu from piwigo's config to AMM config
     304     */
     305    private function backupMenuConfig($updateMenu=false)
     306    {
     307      global $conf;
     308
     309      $this->config['amm_old_blk_menubar']=$conf['blk_menubar'];
     310      pwg_query("UPDATE ".CONFIG_TABLE." SET value = '' WHERE param='blk_menubar';");
     311
     312      if($updateMenu)
     313      {
     314        $tmp=unserialize($conf['blk_menubar']);
     315        foreach($tmp as $key => $val)
    156316        {
    157           $this->config['amm_sections_items'][$key]['translation'] = $this->defaultMenus[$key]['translation'];
     317          pwg_query("REPLACE INTO ".$this->tables['blocks']." VALUES ('$key', '".abs($val)."', '".($val<0?'guest,generic,normal,webmaster,admin':'')."', '');");
    158318        }
    159319      }
    160320    }
    161321
     322    /**
     323     * restore piwigo's menu
     324     */
     325    private function restoreMenuConfig()
     326    {
     327      pwg_query("UPDATE ".CONFIG_TABLE." SET value = '".pwg_db_real_escape_string($this->config['amm_old_blk_menubar'])."' WHERE param='blk_menubar';");
     328    }
     329
     330
     331
    162332  } //class
    163333
Note: See TracChangeset for help on using the changeset viewer.