source: extensions/BatchDownloader/maintain.inc.php @ 16695

Last change on this file since 16695 was 16689, checked in by mistic100, 12 years ago

-separate "archive_comment" in a new config parameter
-confirmation message before start download

File size: 2.9 KB
Line 
1<?php
2if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
3
4define(
5  'batch_download_default_config', 
6  serialize(array(
7    'groups'          => array(),
8    'level'           => 0,
9    'photo_size'      => 'original',
10    'archive_prefix'  => 'piwigo',
11    'archive_timeout' => 48, /* hours */
12    'max_elements'    => 500,
13    'max_size'        => 100, /* MB */
14    'last_clean'      => time(),
15    ))
16  );
17
18function plugin_install() 
19{
20  global $conf, $prefixeTable;
21 
22  $query = '
23CREATE TABLE IF NOT EXISTS `' . $prefixeTable . 'download_sets` (
24  `id` mediumint(8) NOT NULL AUTO_INCREMENT,
25  `user_id` smallint(5) NOT NULL,
26  `date_creation` datetime NOT NULL,
27  `type` varchar(16) CHARACTER SET utf8 NOT NULL,
28  `type_id` varchar(64) CHARACTER SET utf8 NOT NULL,
29  `nb_zip` smallint(3) NOT NULL DEFAULT 0,
30  `last_zip` smallint(3) NOT NULL DEFAULT 0,
31  `nb_images` mediumint(8) NOT NULL DEFAULT 0,
32  `total_size` int(10) NOT NULL DEFAULT 0,
33  `status` enum("new","download","done") CHARACTER SET utf8 NOT NULL DEFAULT "new",
34  PRIMARY KEY (`id`)
35) DEFAULT CHARSET=utf8 AUTO_INCREMENT=1
36;';
37  pwg_query($query);
38 
39  $query = '
40CREATE TABLE IF NOT EXISTS `' . $prefixeTable . 'download_sets_images` (
41  `set_id` mediumint(8) NOT NULL,
42  `image_id` mediumint(8) NOT NULL,
43  `zip` smallint(5) NOT NULL DEFAULT 0,
44  UNIQUE KEY `UNIQUE` (`set_id`,`image_id`)
45) DEFAULT CHARSET=utf8
46;';
47  pwg_query($query);
48
49  conf_update_param('batch_download', batch_download_default_config);
50  conf_update_param('batch_download_comment', null);
51 
52  mkdir($conf['data_location'] . 'download_archives/', 0755);
53}
54
55function plugin_activate()
56{
57  global $conf;
58
59  if (empty($conf['batch_download_comment']))
60  {
61    $new_conf = unserialize($conf['batch_download']);
62    unset($new_conf['archive_comment']);
63    conf_update_param('batch_download', serialize($new_conf));
64    conf_update_param('batch_download_comment', null);
65  }
66 
67  if (!file_exists($conf['data_location'] . 'download_archives/'))
68  {
69    mkdir($conf['data_location'] . 'download_archives/', 0755);
70  }
71}
72
73function plugin_uninstall() 
74{
75  global $prefixeTable, $conf;
76 
77  pwg_query('DELETE FROM `' . CONFIG_TABLE . '` WHERE param = "batch_download" LIMIT 1;');
78  pwg_query('DROP TABLE IF EXISTS `' . $prefixeTable . 'download_sets`;');
79  pwg_query('DROP TABLE IF EXISTS `' . $prefixeTable . 'download_sets_images`;');
80 
81  rrmdir($conf['data_location'].'download_archives/');
82}
83
84function rrmdir($dir)
85{
86  if (!is_dir($dir))
87  {
88    return false;
89  }
90  $dir = rtrim($dir, '/');
91  $objects = scandir($dir);
92  $return = true;
93 
94  foreach ($objects as $object)
95  {
96    if ($object !== '.' && $object !== '..')
97    {
98      $path = $dir.'/'.$object;
99      if (filetype($path) == 'dir') 
100      {
101        $return = $return && rrmdir($path); 
102      }
103      else 
104      {
105        $return = $return && @unlink($path);
106      }
107    }
108  }
109 
110  return $return && @rmdir($dir);
111} 
112
113?>
Note: See TracBrowser for help on using the repository browser.