Ignore:
Timestamp:
Mar 11, 2014, 11:25:49 PM (10 years ago)
Author:
plg
Message:

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:
1 edited

Legend:

Unmodified
Added
Removed
  • extensions/AddUsersNotes/maintain.inc.php

    r12447 r27697  
    11<?php
    2 
    32if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
    43
    5 function plugin_install()
     4class AddUsersNotes_maintain extends PluginMaintain
    65{
     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  {
    715    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    }
    823
    9 if (!defined('USERNOTES_TABLE')) define('USERNOTES_TABLE', $prefixeTable.'user_notes');
    10         $query = "CREATE TABLE IF NOT EXISTS ". USERNOTES_TABLE ." (
    11 user_id SMALLINT( 5 ) UNSIGNED NOT NULL ,
    12 note VARCHAR( 255 ) NOT NULL ,
    13 PRIMARY KEY (user_id))DEFAULT CHARSET=utf8;";
    14         $result = pwg_query($query);
    15        
     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  }
    1660}
    17 
    18 function plugin_uninstall()
    19 {
    20         global $prefixeTable;
    21 
    22         $q = 'DROP TABLE ' . $prefixeTable . 'user_notes;';
    23     pwg_query($q);
    24 }
    25 
    26 
    2761?>
Note: See TracChangeset for help on using the changeset viewer.