source: extensions/ColorStat/cstat_install.class.inc.php @ 5961

Last change on this file since 5961 was 5961, checked in by grum, 14 years ago

Add plugin files

  • Property svn:executable set to *
File size: 4.0 KB
Line 
1<?php
2/* -----------------------------------------------------------------------------
3  Plugin     : ColorStat
4  Author     : Grum
5    email    : grum@piwigo.org
6    website  : http://photos.grum.fr
7
8    << May the Little SpaceFrog be with you ! >>
9  ------------------------------------------------------------------------------
10  See main.inc.php for release information
11
12  CStat_Install : classe to manage plugin install
13
14  --------------------------------------------------------------------------- */
15
16   include_once('cstat_version.inc.php'); // => Don't forget to update this file !!
17   include_once('cstat_root.class.inc.php');
18   include_once(PHPWG_PLUGINS_PATH.'GrumPluginClasses/classes/GPCTables.class.inc.php');
19
20  /* CStat class for install process */
21  class CStat_Install extends CStat_root
22  {
23    private $tablef;
24
25    public function __construct($prefixeTable, $filelocation)
26    {
27      parent::__construct($prefixeTable, $filelocation);
28      $this->tablef= new GPCTables($this->tables);
29    }
30
31    public function __destruct()
32    {
33      unset($this->tablef);
34      parent::__destruct();
35    }
36
37    /*
38        function for installation process
39        return true if install process is ok, otherwise false
40    */
41    public function install()
42    {
43      $this->initConfig();
44      $this->loadConfig();
45      $this->config['installed']=CSTAT_VERSION2;
46      $this->config['newInstall']='y';
47      $this->saveConfig();
48
49      $tables_def=array(
50"CREATE TABLE `".$this->tables['color_table']."` (
51  `color_id` CHAR(6)  NOT NULL DEFAULT 000000,
52  `hue` INT UNSIGNED NOT NULL DEFAULT 0,
53  `saturation` INT UNSIGNED NOT NULL DEFAULT 0,
54  `value` INT UNSIGNED NOT NULL DEFAULT 0,
55  `num_images` INT UNSIGNED NOT NULL DEFAULT 0,
56  `num_pixels` INT UNSIGNED NOT NULL DEFAULT 0,
57  PRIMARY KEY (`color_id`),
58  INDEX `hue`(`hue`)
59)
60CHARACTER SET utf8 COLLATE utf8_general_ci",
61
62"CREATE TABLE `".$this->tables['images_colors']."` (
63  `image_id` MEDIUMINT(8) UNSIGNED NOT NULL DEFAULT 0,
64  `color_id` CHAR(6)  NOT NULL DEFAULT 000000,
65  `pct` float unsigned NOT NULL default '0',
66  `num_pixels` INT UNSIGNED NOT NULL DEFAULT 0,
67  PRIMARY KEY (`image_id`, `color_id`),
68  KEY `by_color` (`pct`,`color_id`)
69)
70CHARACTER SET utf8 COLLATE utf8_general_ci",
71
72"CREATE TABLE `".$this->tables['images']."` (
73  `image_id` mediumint(8) unsigned NOT NULL,
74  `analyzed` char(1) NOT NULL default 'n',
75  `num_colors` int(10) unsigned NOT NULL default '0',
76  `num_pixels` int(10) unsigned NOT NULL default '0',
77  `analyzed_pixels` int(10) unsigned NOT NULL default '0',
78  `pps` int(10) unsigned NOT NULL default '0',
79  `time` float unsigned NOT NULL default '0',
80  `quality` tinyint(4) NOT NULL default '0',
81  PRIMARY KEY  (`image_id`),
82  KEY `by_analyzed` (`analyzed`)
83)",
84
85      );
86
87      $result=$this->tablef->create($tables_def);
88      return($result);
89    }
90
91
92    /*
93        function for uninstall process
94    */
95    public function uninstall()
96    {
97      $this->deleteConfig();
98      $this->tablef->drop();
99      return('');
100    }
101
102    public function activate()
103    {
104      global $template;
105
106      $this->initConfig();
107      //$this->loadConfig(); //don't keep the previous config : we need to start with default values
108      $this->config['installed']=CSTAT_VERSION2;
109      $this->config['newInstall']='y';
110      $this->saveConfig();
111
112      pwg_query("DELETE FROM ".$this->tables['color_table']);
113      pwg_query("DELETE FROM ".$this->tables['images_colors']);
114      pwg_query("UPDATE ".$this->tables['images']."
115                  SET analyzed='n',
116                      num_colors=0,
117                      num_pixels=0,
118                      analyzed_pixels=0,
119                      pps=0,
120                      time=0,
121                      quality=0;");
122      pwg_query("INSERT INTO ".$this->tables['images']."
123                  SELECT id, 'n', 0, 0, 0, 0, 0, 0
124                    FROM ".IMAGES_TABLE."
125                    WHERE id NOT IN (SELECT image_id FROM ".$this->tables['images'].")");
126
127      return('');
128    }
129
130    public function deactivate()
131    {
132    }
133
134  } //class
135
136?>
Note: See TracBrowser for help on using the repository browser.