Ignore:
Timestamp:
Jan 4, 2014, 4:13:08 PM (10 years ago)
Author:
mistic100
Message:

update for Piwigo 2.6

File:
1 edited

Legend:

Unmodified
Added
Removed
  • extensions/SmartAlbums/maintain.inc.php

    r21658 r26442  
    11<?php
    2 if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
     2defined('PHPWG_ROOT_PATH') or die('Hacking attempt!');
    33
    4 include_once(PHPWG_PLUGINS_PATH . 'SmartAlbums/include/install.inc.php');
     4class SmartAlbums_maintain extends PluginMaintain
     5{
     6  private $installed = false;
    57
    6 function plugin_install()
    7 {
    8   smart_albums_install();
    9   define('smart_albums_installed', true);
    10 }
     8  private $default_conf = array(
     9    'update_on_upload' => false,
     10    'update_on_date' => true,
     11    'update_timeout' => 3,
     12    'show_list_messages' => true,
     13    'smart_is_forbidden' => false,
     14    'last_update' => 0,
     15    );
    1116
    12 function plugin_activate()
    13 {
    14   if (!defined('smart_albums_installed'))
     17  private $table;
     18
     19  function __construct($plugin_id)
    1520  {
    16     smart_albums_install();
     21    global $prefixeTable;
     22
     23    parent::__construct($plugin_id);
     24
     25    $this->table = $prefixeTable . 'category_filters';
     26  }
     27
     28  function install($plugin_version, &$errors=array())
     29  {
     30    global $conf, $prefixeTable;
     31
     32    if (empty($conf['SmartAlbums']))
     33    {
     34      $conf['SmartAlbums'] = serialize($this->default_conf);
     35      conf_update_param('SmartAlbums', $conf['SmartAlbums']);
     36    }
     37    else
     38    {
     39      $new_conf = is_string($conf['SmartAlbums']) ? unserialize($conf['SmartAlbums']) : $conf['SmartAlbums'];
     40
     41      // new param in 2.0.2
     42      if (!isset($new_conf['smart_is_forbidden']))
     43      {
     44        $new_conf['smart_is_forbidden'] = true;
     45      }
     46
     47      // new params in 2.1.0
     48      if (!isset($new_conf['update_on_date']))
     49      {
     50        $new_conf['update_on_date'] = true;
     51        $new_conf['update_timeout'] = 3;
     52        $new_conf['last_update'] = 0;
     53      }
     54
     55      $conf['SmartAlbums'] = serialize($new_conf);
     56      conf_update_param('SmartAlbums', $conf['SmartAlbums']);
     57    }
     58
     59    // new table
     60    pwg_query(
     61'CREATE TABLE IF NOT EXISTS `' . $this->table . '` (
     62  `category_id` smallint(5) unsigned NOT NULL,
     63  `type` varchar(16) NOT NULL,
     64  `cond` varchar(16) NULL,
     65  `value` text NULL,
     66  `updated` DATETIME NOT NULL DEFAULT "1970-01-01 00:00:00"
     67) ENGINE=MyISAM DEFAULT CHARSET=utf8
     68;');
     69
     70    // new column on image category table
     71    $result = pwg_query('SHOW COLUMNS FROM `' . IMAGE_CATEGORY_TABLE . '` LIKE "smart";');
     72    if (!pwg_db_num_rows($result))
     73    {
     74      pwg_query('ALTER TABLE `' . IMAGE_CATEGORY_TABLE . '` ADD `smart` ENUM(\'true\', \'false\') NOT NULL DEFAULT \'false\';');
     75    }
     76
     77    // new column on category filters table (2.1.1)
     78    $result = pwg_query('SHOW COLUMNS FROM `' . $this->table . '` LIKE "updated";');
     79    if (!pwg_db_num_rows($result))
     80    {
     81      pwg_query('ALTER TABLE `' . $this->table . '` ADD `updated` DATETIME NOT NULL DEFAULT "1970-01-01 00:00:00"');
     82    }
     83
     84    // remove column on category table, moved to category filters table (2.1.1)
     85    $result = pwg_query('SHOW COLUMNS FROM `' . CATEGORIES_TABLE . '` LIKE "smart_update";');
     86    if (pwg_db_num_rows($result))
     87    {
     88      pwg_query('UPDATE `' . $this->table . '` AS f SET updated = ( SELECT smart_update FROM `' . CATEGORIES_TABLE . '` AS c WHERE c.id = f.category_id );');
     89      pwg_query('ALTER TABLE `' . CATEGORIES_TABLE . '` DROP `smart_update`;');
     90    }
     91
     92    // date filters renamed in 2.0
     93    $query = '
     94SELECT category_id
     95  FROM `' . $this->table . '`
     96  WHERE
     97    type = "date" AND
     98    cond IN ("the","before","after","the_crea","before_crea","after_crea")
     99;';
     100
     101    if (pwg_db_num_rows(pwg_query($query)))
     102    {
     103      $name_changes = array(
     104        'the' => 'the_post',
     105        'before' => 'before_post',
     106        'after' => 'after_post',
     107        'the_crea' => 'the_taken',
     108        'before_crea' => 'before_taken',
     109        'after_crea' => 'after_taken',
     110        );
     111      foreach ($name_changes as $old => $new)
     112      {
     113        pwg_query('UPDATE `' . $this->table . '` SET cond = "' . $new . '" WHERE type = "date" AND cond = "' . $old . '";');
     114      }
     115    }
     116
     117    $this->installed = true;
     118  }
     119
     120  function activate($plugin_version, &$errors=array())
     121  {
     122    if (!$this->installed)
     123    {
     124      $this->install($plugin_version, $errors);
     125    }
     126  }
     127
     128  function deactivate()
     129  {
     130  }
     131
     132  function uninstall()
     133  {
     134    conf_delete_param('SmartAlbums');
     135
     136    pwg_query('DROP TABLE `' . $this->table . '`;');
     137
     138    pwg_query('ALTER TABLE `' . IMAGE_CATEGORY_TABLE . '` DROP `smart`;');
    17139  }
    18140}
    19 
    20 function plugin_uninstall()
    21 {
    22   global $prefixeTable;
    23  
    24   pwg_query('DROP TABLE `' . $prefixeTable . 'category_filters`;');
    25   pwg_query('ALTER TABLE `' . IMAGE_CATEGORY_TABLE . '` DROP `smart`;');
    26   pwg_query('DELETE FROM `' . CONFIG_TABLE . '` WHERE param = \'SmartAlbums\' LIMIT 1;');
    27 }
    28 
    29 ?>
Note: See TracChangeset for help on using the changeset viewer.