[5961] | 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 | |
---|
[6107] | 16 | if(!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
---|
[5961] | 17 | |
---|
[6107] | 18 | include_once('cstat_version.inc.php'); // => Don't forget to update this file !! |
---|
| 19 | include_once('cstat_root.class.inc.php'); |
---|
| 20 | include_once(PHPWG_PLUGINS_PATH.'GrumPluginClasses/classes/GPCTables.class.inc.php'); |
---|
| 21 | include_once(PHPWG_PLUGINS_PATH.'GrumPluginClasses/classes/GPCRequestBuilder.class.inc.php'); |
---|
| 22 | |
---|
[5961] | 23 | /* CStat class for install process */ |
---|
| 24 | class CStat_Install extends CStat_root |
---|
| 25 | { |
---|
| 26 | private $tablef; |
---|
| 27 | |
---|
| 28 | public function __construct($prefixeTable, $filelocation) |
---|
| 29 | { |
---|
| 30 | parent::__construct($prefixeTable, $filelocation); |
---|
| 31 | $this->tablef= new GPCTables($this->tables); |
---|
| 32 | } |
---|
| 33 | |
---|
| 34 | public function __destruct() |
---|
| 35 | { |
---|
| 36 | unset($this->tablef); |
---|
| 37 | parent::__destruct(); |
---|
| 38 | } |
---|
| 39 | |
---|
| 40 | /* |
---|
| 41 | function for installation process |
---|
| 42 | return true if install process is ok, otherwise false |
---|
| 43 | */ |
---|
| 44 | public function install() |
---|
| 45 | { |
---|
| 46 | $this->initConfig(); |
---|
| 47 | $this->loadConfig(); |
---|
| 48 | $this->config['installed']=CSTAT_VERSION2; |
---|
| 49 | $this->config['newInstall']='y'; |
---|
| 50 | $this->saveConfig(); |
---|
| 51 | |
---|
| 52 | $tables_def=array( |
---|
| 53 | "CREATE TABLE `".$this->tables['color_table']."` ( |
---|
| 54 | `color_id` CHAR(6) NOT NULL DEFAULT 000000, |
---|
| 55 | `hue` INT UNSIGNED NOT NULL DEFAULT 0, |
---|
| 56 | `saturation` INT UNSIGNED NOT NULL DEFAULT 0, |
---|
| 57 | `value` INT UNSIGNED NOT NULL DEFAULT 0, |
---|
| 58 | `num_images` INT UNSIGNED NOT NULL DEFAULT 0, |
---|
| 59 | `num_pixels` INT UNSIGNED NOT NULL DEFAULT 0, |
---|
| 60 | PRIMARY KEY (`color_id`), |
---|
| 61 | INDEX `hue`(`hue`) |
---|
| 62 | ) |
---|
| 63 | CHARACTER SET utf8 COLLATE utf8_general_ci", |
---|
| 64 | |
---|
| 65 | "CREATE TABLE `".$this->tables['images_colors']."` ( |
---|
| 66 | `image_id` MEDIUMINT(8) UNSIGNED NOT NULL DEFAULT 0, |
---|
| 67 | `color_id` CHAR(6) NOT NULL DEFAULT 000000, |
---|
| 68 | `pct` float unsigned NOT NULL default '0', |
---|
| 69 | `num_pixels` INT UNSIGNED NOT NULL DEFAULT 0, |
---|
| 70 | PRIMARY KEY (`image_id`, `color_id`), |
---|
| 71 | KEY `by_color` (`pct`,`color_id`) |
---|
| 72 | ) |
---|
| 73 | CHARACTER SET utf8 COLLATE utf8_general_ci", |
---|
| 74 | |
---|
| 75 | "CREATE TABLE `".$this->tables['images']."` ( |
---|
| 76 | `image_id` mediumint(8) unsigned NOT NULL, |
---|
| 77 | `analyzed` char(1) NOT NULL default 'n', |
---|
| 78 | `num_colors` int(10) unsigned NOT NULL default '0', |
---|
| 79 | `num_pixels` int(10) unsigned NOT NULL default '0', |
---|
| 80 | `analyzed_pixels` int(10) unsigned NOT NULL default '0', |
---|
| 81 | `pps` int(10) unsigned NOT NULL default '0', |
---|
| 82 | `time` float unsigned NOT NULL default '0', |
---|
| 83 | `quality` tinyint(4) NOT NULL default '0', |
---|
[6107] | 84 | `colors` char(111) NOT NULL default '', |
---|
| 85 | `colors_pct` char(111) NOT NULL default '', |
---|
[5961] | 86 | PRIMARY KEY (`image_id`), |
---|
| 87 | KEY `by_analyzed` (`analyzed`) |
---|
| 88 | )", |
---|
| 89 | ); |
---|
| 90 | |
---|
| 91 | $result=$this->tablef->create($tables_def); |
---|
| 92 | return($result); |
---|
| 93 | } |
---|
| 94 | |
---|
| 95 | |
---|
| 96 | /* |
---|
| 97 | function for uninstall process |
---|
| 98 | */ |
---|
| 99 | public function uninstall() |
---|
| 100 | { |
---|
| 101 | $this->deleteConfig(); |
---|
| 102 | $this->tablef->drop(); |
---|
| 103 | return(''); |
---|
| 104 | } |
---|
| 105 | |
---|
| 106 | public function activate() |
---|
| 107 | { |
---|
| 108 | global $template; |
---|
| 109 | |
---|
| 110 | $this->initConfig(); |
---|
| 111 | //$this->loadConfig(); //don't keep the previous config : we need to start with default values |
---|
| 112 | $this->config['installed']=CSTAT_VERSION2; |
---|
| 113 | $this->config['newInstall']='y'; |
---|
| 114 | $this->saveConfig(); |
---|
| 115 | |
---|
| 116 | pwg_query("DELETE FROM ".$this->tables['color_table']); |
---|
| 117 | pwg_query("DELETE FROM ".$this->tables['images_colors']); |
---|
| 118 | pwg_query("UPDATE ".$this->tables['images']." |
---|
| 119 | SET analyzed='n', |
---|
| 120 | num_colors=0, |
---|
| 121 | num_pixels=0, |
---|
| 122 | analyzed_pixels=0, |
---|
| 123 | pps=0, |
---|
| 124 | time=0, |
---|
| 125 | quality=0;"); |
---|
| 126 | pwg_query("INSERT INTO ".$this->tables['images']." |
---|
[6176] | 127 | SELECT id, 'n', 0, 0, 0, 0, 0, 0, '', '' |
---|
[5961] | 128 | FROM ".IMAGES_TABLE." |
---|
| 129 | WHERE id NOT IN (SELECT image_id FROM ".$this->tables['images'].")"); |
---|
| 130 | |
---|
| 131 | return(''); |
---|
| 132 | } |
---|
| 133 | |
---|
| 134 | public function deactivate() |
---|
| 135 | { |
---|
| 136 | } |
---|
| 137 | |
---|
| 138 | } //class |
---|
| 139 | |
---|
| 140 | ?> |
---|