Ignore:
Timestamp:
Dec 12, 2013, 2:41:53 PM (10 years ago)
Author:
mistic100
Message:

update for Piwigo 2.6 + code cleaning + fix unable to cancel set during generation

File:
1 edited

Legend:

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

    r19837 r25932  
    22if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
    33
    4 defined('BATCH_DOWNLOAD_ID') or define('BATCH_DOWNLOAD_ID', basename(dirname(__FILE__)));
    5 include_once(PHPWG_PLUGINS_PATH . BATCH_DOWNLOAD_ID . '/include/install.inc.php');
     4class BatchDownloader_maintain extends PluginMaintain
     5{
     6  private $installed = false;
    67
    7 function plugin_install()
    8 {
    9   batch_download_install();
    10  
    11   define('batch_download_installed', true);
    12 }
     8  function install($plugin_version, &$errors=array())
     9  {
     10    global $conf, $prefixeTable;
    1311
    14 function plugin_activate()
    15 {
    16   if (!defined('batch_download_installed'))
     12    // configuration
     13    if (empty($conf['batch_download']))
     14    {
     15      $batch_download_default_config = array(
     16        'groups'          => array(),
     17        'level'           => 0,
     18        'what'            => array('categories','specials','collections'),
     19        'photo_size'      => 'original',
     20        'multisize'       => true,
     21        'archive_prefix'  => 'piwigo',
     22        'archive_timeout' => 48, /* hours */
     23        'max_elements'    => 500,
     24        'max_size'        => 100, /* MB */
     25        'last_clean'      => time(),
     26        'one_archive'     => false,
     27        'force_pclzip'    => false,
     28        'direct'          => false,
     29        );
     30
     31      $conf['batch_download'] = serialize($batch_download_default_config);
     32      $conf['batch_download_comment'] = null;
     33
     34      conf_update_param('batch_download', $conf['batch_download']);
     35      conf_update_param('batch_download_comment', $conf['batch_download_comment']);
     36    }
     37    else
     38    {
     39      $new_conf = is_string($conf['batch_download']) ? unserialize($conf['batch_download']) : $conf['batch_download'];
     40
     41      if (!isset($new_conf['what']))
     42      {
     43        $new_conf['what'] = array('categories','specials','collections');
     44      }
     45      if (!isset($new_conf['one_archive']))
     46      {
     47        $new_conf['one_archive'] = false;
     48        $new_conf['force_pclzip'] = isset($conf['batch_download_force_pclzip']) && $conf['batch_download_force_pclzip'];
     49        $new_conf['direct'] = isset($conf['batch_download_direct']) && $conf['batch_download_direct'];
     50      }
     51      if (!isset($new_conf['multisize']))
     52      {
     53        $new_conf['multisize'] = true;
     54      }
     55
     56      $conf['batch_download'] = serialize($new_conf);
     57      conf_update_param('batch_download', $conf['batch_download']);
     58    }
     59
     60    // archives directory
     61    if (!file_exists(PHPWG_ROOT_PATH . $conf['data_location'] . 'download_archives/'))
     62    {
     63      mkgetdir(PHPWG_ROOT_PATH . $conf['data_location'] . 'download_archives/', MKGETDIR_DEFAULT&~MKGETDIR_DIE_ON_ERROR);
     64    }
     65
     66    // create tables
     67    $query = '
     68CREATE TABLE IF NOT EXISTS `' . $prefixeTable . 'download_sets` (
     69  `id` mediumint(8) NOT NULL AUTO_INCREMENT,
     70  `user_id` smallint(5) NOT NULL,
     71  `date_creation` datetime NOT NULL,
     72  `type` varchar(16) NOT NULL,
     73  `type_id` varchar(64) NOT NULL,
     74  `size` varchar(16) NOT NULL DEFAULT "original",
     75  `nb_zip` smallint(3) NOT NULL DEFAULT 0,
     76  `last_zip` smallint(3) NOT NULL DEFAULT 0,
     77  `nb_images` mediumint(8) NOT NULL DEFAULT 0,
     78  `total_size` int(10) NOT NULL DEFAULT 0,
     79  `status` enum("new","ready","download","done") NOT NULL DEFAULT "new",
     80  PRIMARY KEY (`id`)
     81) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1
     82;';
     83    pwg_query($query);
     84
     85    $query = '
     86CREATE TABLE IF NOT EXISTS `' . $prefixeTable . 'download_sets_images` (
     87  `set_id` mediumint(8) NOT NULL,
     88  `image_id` mediumint(8) NOT NULL,
     89  `zip` smallint(5) NOT NULL DEFAULT 0,
     90  UNIQUE KEY `UNIQUE` (`set_id`,`image_id`)
     91) ENGINE=MyISAM DEFAULT CHARSET=utf8
     92;';
     93    pwg_query($query);
     94
     95    $query = '
     96CREATE TABLE IF NOT EXISTS `' . $prefixeTable . 'image_sizes` (
     97  `image_id` mediumint(8) NOT NULL,
     98  `type` varchar(16) NOT NULL,
     99  `width` smallint(9) NOT NULL,
     100  `height` smallint(9) NOT NULL,
     101  `filesize` mediumint(9) NOT NULL,
     102  `filemtime` int(16) NOT NULL,
     103  PRIMARY KEY (`image_id`)
     104) ENGINE=MyISAM DEFAULT CHARSET=utf8
     105;';
     106    pwg_query($query);
     107
     108    // add a "size" column to download_sets
     109    $result = pwg_query('SHOW COLUMNS FROM `' . $prefixeTable . 'download_sets` LIKE "size";');
     110    if (!pwg_db_num_rows($result))
     111    {
     112      pwg_query('ALTER TABLE `' . $prefixeTable . 'download_sets` ADD `size` varchar(16) NOT NULL DEFAULT "original";');
     113    }
     114
     115    // add "ready" status
     116    pwg_query('ALTER TABLE `' . $prefixeTable . 'download_sets` CHANGE `status` `status` enum("new","ready","download","done") NOT NULL DEFAULT "new";');
     117  }
     118
     119  function activate($plugin_version, &$errors=array())
    17120  {
    18     batch_download_install();
     121    if (!$this->installed)
     122    {
     123      $this->install($plugin_version, $errors);
     124    }
    19125  }
    20 }
    21126
    22 function plugin_uninstall()
    23 {
    24   global $prefixeTable, $conf;
    25  
    26   pwg_query('DELETE FROM `' . CONFIG_TABLE . '` WHERE param = "batch_download" LIMIT 1;');
    27   pwg_query('DROP TABLE IF EXISTS `' . $prefixeTable . 'download_sets`;');
    28   pwg_query('DROP TABLE IF EXISTS `' . $prefixeTable . 'download_sets_images`;');
    29  
    30   rrmdir(PHPWG_ROOT_PATH . $conf['data_location'] . 'download_archives/');
    31 }
     127  function deactivate()
     128  {
     129  }
    32130
     131  function uninstall()
     132  {
     133    global $prefixeTable, $conf;
    33134
    34 if (!function_exists('rrmdir'))
    35 {
    36   function rrmdir($dir)
     135    conf_delete_param('batch_download');
     136
     137    pwg_query('DROP TABLE IF EXISTS `' . $prefixeTable . 'download_sets`;');
     138    pwg_query('DROP TABLE IF EXISTS `' . $prefixeTable . 'download_sets_images`;');
     139
     140    self::rrmdir(PHPWG_ROOT_PATH . $conf['data_location'] . 'download_archives/');
     141  }
     142
     143  static function rrmdir($dir)
    37144  {
    38145    if (!is_dir($dir))
     
    43150    $objects = scandir($dir);
    44151    $return = true;
    45    
     152
    46153    foreach ($objects as $object)
    47154    {
     
    49156      {
    50157        $path = $dir.'/'.$object;
    51         if (filetype($path) == 'dir') 
     158        if (filetype($path) == 'dir')
    52159        {
    53           $return = $return && rrmdir($path);
     160          $return = $return && self::rrmdir($path);
    54161        }
    55         else 
     162        else
    56163        {
    57164          $return = $return && @unlink($path);
     
    59166      }
    60167    }
    61    
     168
    62169    return $return && @rmdir($dir);
    63170  }
    64171}
    65 
    66 ?>
Note: See TracChangeset for help on using the changeset viewer.