source: extensions/AddUsersNotes/maintain.inc.php @ 29412

Last change on this file since 29412 was 27697, checked in by plg, 11 years ago

compatibility with Piwigo 2.6 new user manager

relies on a new trigger ws_users_getList (for Piwigo 2.6.2)

Replace table piwigo_user_notes by column piwigo_user_infos.usernotes (simpler
coding for the plugin and automatic management of column in user manager table)

File size: 1.3 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 deactivate()
53  {
54  }
55
56  function uninstall()
57  {
58    pwg_query('ALTER TABLE `'. USER_INFOS_TABLE .'` DROP `usernotes`;');
59  }
60}
61?>
Note: See TracBrowser for help on using the repository browser.