Changeset 27330


Ignore:
Timestamp:
Feb 11, 2014, 1:25:40 PM (7 years ago)
Author:
JanisV
Message:

Updated storing association physical 2 virtual

Location:
extensions/physical2virtual
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • extensions/physical2virtual/language/ru_RU/plugin.lang.php

    r27229 r27330  
    55$lang['Make physical albums private after converting'] = 'Делать физические альбомы приватными после конвертирования';
    66$lang['Convert now'] = 'Конвертировать сейчас';
     7$lang['Convertion done'] = 'Конвертирование выполнено';
    78$lang['Store folder structure'] = 'Сохранять структуру папок';
    89$lang['Unlock new virtual albums when possible'] = 'Разблокировать новые виртуальные альбомы когда возможно';
  • extensions/physical2virtual/main.inc.php

    r27229 r27330  
    22/*
    33Plugin Name: physical2virtual
    4 Version: 2.6.d
     4Version: 2.6.e
    55Description: Autoconvert physical albums to virtual
    66Plugin URI: http://piwigo.org/ext/extension_view.php?eid=730
     
    1010if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
    1111
     12global $prefixeTable;
     13
    1214define('PHYSICAL2VIRTUAL_ID',       basename(dirname(__FILE__)));
    1315define('PHYSICAL2VIRTUAL_PATH' ,    PHPWG_PLUGINS_PATH . PHYSICAL2VIRTUAL_ID . '/');
    1416define('PHYSICAL2VIRTUAL_ADMIN',    get_root_url() . 'admin.php?page=plugin-' . PHYSICAL2VIRTUAL_ID);
     17define('PHY2VIRT_CATEGORIES_TABLE', $prefixeTable . 'phy2virt_categories');
    1518
    1619add_event_handler('init', 'physical2virtual_init');
     
    3134}
    3235
    33 function find_or_create_virtual_category($category_name, $parent_id=null, $options=array())
     36function find_or_create_virtual_category($phy_category, $parent_id=null, $options=array())
    3437{
     38  $query = '
     39SELECT DISTINCT virt_category_id AS id
     40  FROM '.PHY2VIRT_CATEGORIES_TABLE.'
     41  WHERE phy_category_id = '.$phy_category['id'].'
     42;';
     43  $virt_category = pwg_db_fetch_assoc(pwg_query($query));
     44  if (!empty($virt_category))
     45  {
     46    return $virt_category; /// add $virt_cat['representative_picture_id']
     47  }
     48 
     49  $category_name = $phy_category['name'];
    3550  // process empty album name
    3651  if (preg_match('/^\s*$/', $category_name))
     
    5065  }
    5166
    52   return create_virtual_category($category_name, $parent_id, $options);
     67  $cat = create_virtual_category($category_name, $parent_id, $options);
     68  $insert = array(
     69    'phy_category_id' => $phy_category['id'],
     70    'virt_category_id' => $cat['id'],
     71//    'updated' => date('Y-m-d H:i:s'),
     72    );
     73  single_insert(PHY2VIRT_CATEGORIES_TABLE, $insert);
     74
     75  return $cat;
    5376}
    5477
     
    6285  $options['inherit'] = $conf['physical2virtual']['inherit'];
    6386
     87  // Remove virtual without physical
     88  $query = '
     89    SELECT virt_category_id
     90    FROM '.PHY2VIRT_CATEGORIES_TABLE.'
     91    WHERE phy_category_id NOT IN (
     92      SELECT cat.id
     93      FROM '.CATEGORIES_TABLE.' cat
     94      WHERE cat.dir IS NOT NULL
     95    )
     96  ;';
     97  $category_ids = array_from_query($query, 'virt_category_id');
     98  delete_categories($category_ids);
     99
     100  $query = '
     101    DELETE FROM '.PHY2VIRT_CATEGORIES_TABLE.'
     102    WHERE phy_category_id NOT IN (
     103      SELECT cat.id
     104      FROM '.CATEGORIES_TABLE.' cat
     105      WHERE cat.dir IS NOT NULL
     106    )
     107  ;';
     108  pwg_query($query);
     109 
    64110  $query = '
    65111    SELECT id, name, id_uppercat
     
    70116  while ($row = pwg_db_fetch_assoc($result))
    71117  {
    72     $virt_name = $row['name'];
    73 
    74118    $parent = isset($conf['physical2virtual']['parent_cat']) ? $conf['physical2virtual']['parent_cat'] : null;
    75119       
     
    83127      foreach ($uppers as $upper)
    84128      {
    85         $parent = find_or_create_virtual_category($upper['name'], $parent, $options)['id'];
     129        $parent = find_or_create_virtual_category($upper, $parent, $options)['id'];
    86130      }
    87131    }
    88132
    89     $virt_cat = find_or_create_virtual_category($virt_name, $parent, $options);
    90 //    $virt_cat = create_virtual_category($virt_name, $parent, $options); // use this for duplicate folders name
     133    $virt_cat = find_or_create_virtual_category($row, $parent, $options);
    91134
    92135    if (isset($conf['physical2virtual']['lock_physical']) and $conf['physical2virtual']['lock_physical'])
     
    106149      INSERT IGNORE INTO '.IMAGE_CATEGORY_TABLE.' (category_id, image_id)
    107150        SELECT '.$virt_cat['id'].', image_id FROM '.IMAGE_CATEGORY_TABLE.' WHERE category_id = '.$row['id'].'
     151    ;';
     152    pwg_query($query);
     153
     154    $query = '
     155UPDATE '.PHY2VIRT_CATEGORIES_TABLE.'
     156  SET updated = NOW()
     157  WHERE virt_category_id = '.$virt_cat['id'].'
    108158    ;';
    109159    pwg_query($query);
  • extensions/physical2virtual/maintain.inc.php

    r27229 r27330  
    2727  function __construct($plugin_id)
    2828  {
     29    global $prefixeTable;
     30
    2931    parent::__construct($plugin_id);
     32
     33    $this->table = $prefixeTable . 'phy2virt_categories';
    3034  }
    3135
    3236  function install($plugin_version, &$errors=array())
    3337  {
    34     global $conf;
     38    global $conf, $prefixeTable;
    3539
    3640    if (empty($conf['physical2virtual']))
     
    4751    }
    4852   
     53    // new table
     54    pwg_query(
     55'CREATE TABLE IF NOT EXISTS `' . $this->table . '` (
     56  `phy_category_id` smallint(5) unsigned NOT NULL,
     57  `virt_category_id` smallint(5) unsigned NOT NULL,
     58  `updated` DATETIME NOT NULL DEFAULT "1970-01-01 00:00:00",
     59  KEY `phy_category_id` (`phy_category_id`)
     60) ENGINE=MyISAM DEFAULT CHARSET=utf8
     61;');
     62
    4963    $this->installed = true;
    5064  }
     
    6579  {
    6680    conf_delete_param('physical2virtual');
     81
     82    pwg_query('DROP TABLE `' . $this->table . '`;');
    6783  }
    6884}
Note: See TracChangeset for help on using the changeset viewer.