source: extensions/AddUsersNotes/maintain.class.php @ 32342

Last change on this file since 32342 was 29854, checked in by plg, 10 years ago

compatible with Piwigo 2.7

File size: 1.5 KB
Line 
1<?php
2if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
3
4class AddUsersNotes_maintain extends PluginMaintain
5{
6  private $installed = false;
7
8  function __construct($plugin_id)
9  {
10    parent::__construct($plugin_id);
11  }
12
13  function install($plugin_version, &$errors=array())
14  {
15    global $prefixeTable;
16   
17    // add a new column to existing table
18    $result = pwg_query('SHOW COLUMNS FROM `'.USER_INFOS_TABLE.'` LIKE "usernotes";');
19    if (!pwg_db_num_rows($result))
20    {
21      pwg_query('ALTER TABLE `' . USER_INFOS_TABLE . '` ADD `usernotes` VARCHAR(255) DEFAULT NULL;');
22    }
23
24    // if we find the old table, we copy notes
25    $result = pwg_query('SHOW TABLES LIKE "'.$prefixeTable.'user_notes";');
26    if (pwg_db_num_rows($result))
27    {
28      $query = '
29UPDATE
30    '.USER_INFOS_TABLE.' AS ui,
31    '.$prefixeTable.'user_notes AS un
32  SET ui.usernotes = un.note
33  WHERE ui.user_id = un.user_id
34    AND LENGTH(note) > 0
35;';
36      pwg_query($query);
37
38      pwg_query('DROP TABLE '.$prefixeTable.'user_notes;');
39    }
40   
41    $this->installed = true;
42  }
43
44  function activate($plugin_version, &$errors=array())
45  {
46    if (!$this->installed)
47    {
48      $this->install($plugin_version, $errors);
49    }
50  }
51
52  function update($old_version, $new_version, &$errors=array())
53  {
54    $this->install($new_version, $errors);
55  }
56 
57  function deactivate()
58  {
59  }
60
61  function uninstall()
62  {
63    pwg_query('ALTER TABLE `'. USER_INFOS_TABLE .'` DROP `usernotes`;');
64  }
65}
66?>
Note: See TracBrowser for help on using the repository browser.