Ignore:
Timestamp:
Jun 13, 2013, 2:01:34 PM (11 years ago)
Author:
mistic100
Message:

use serialized array for config + custom upgrade process

Location:
extensions/Back2Front/include
Files:
1 added
1 moved

Legend:

Unmodified
Added
Removed
  • extensions/Back2Front/include/functions.inc.php

    r23167 r23177  
    22if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
    33
    4 /* $item = array('verso_id', 'categories'); */
     4/*
     5 * restore verso to its original categories
     6 * criterias :
     7 *  - verso € 'versos' cat only => restore verso to original categories
     8 *  - otherwise nothing is changed
     9 * 
     10 * $item = array('verso_id', 'categories');
     11*/
    512function back2front_restaure_categories($item)
    613{
    714  global $conf;
    8        
     15 
    916  /* catch current verso categories */
    10   $versos_infos = pwg_query("SELECT category_id FROM ".IMAGE_CATEGORY_TABLE." WHERE image_id = ".$item['verso_id'].";");
    11   $item['current_verso_cats'] = array();
    12   while (list($verso_cat) = pwg_db_fetch_row($versos_infos))
    13   {
    14     $item['current_verso_cats'][] = $verso_cat;
    15   }
     17  $query = 'SELECT DISTINCT category_id FROM '.IMAGE_CATEGORY_TABLE.' WHERE image_id = '.$item['verso_id'].';';
     18  $item['current_verso_cats'] = array_from_query($query, 'category_id');
    1619
    1720  /* if verso € 'versos' cat only */
    18   if (count($item['current_verso_cats']) == 1 AND $item['current_verso_cats'][0] == $conf['back2front'][0])
     21  if (count($item['current_verso_cats']) == 1 && $item['current_verso_cats'][0] == $conf['back2front']['versos_cat'])
    1922  {
    2023    foreach (explode(',',$item['categories']) as $cat)
     
    3639  }
    3740 
    38   pwg_query("DELETE FROM ".IMAGE_CATEGORY_TABLE."
    39     WHERE image_id = ".$item['verso_id']." AND category_id = ".$conf['back2front'][0].";");
     41  $query = '
     42DELETE FROM '.IMAGE_CATEGORY_TABLE.'
     43  WHERE image_id = '.$item['verso_id'].'
     44    AND category_id = '.$conf['back2front']['versos_cat'].'
     45;';
     46  pwg_query($query);
     47}
     48
     49function back2front_check_storage()
     50{
     51  global $conf;
     52 
     53  if ($conf['back2front']['versos_cat'] != 0)
     54  {
     55    $query = '
     56SELECT COUNT(*) FROM '.CATEGORIES_TABLE.'
     57  WHERE id = '.$conf['back2front']['versos_cat'].'
     58    AND name = "Back2Front private album"
     59;';
     60    $result = pwg_query($query);
     61   
     62    if (pwg_db_num_rows($result))
     63    {
     64      return;
     65    }
     66  }
     67 
     68  $versos_cat = create_virtual_category('Back2Front private album');
     69  $versos_cat = array(
     70    'id' => $versos_cat['id'],
     71    'comment' => 'Used by Back2Front to store backsides.',
     72    'status'  => 'private',
     73    'visible' => 'false',
     74    'commentable' => 'false',
     75    );
     76 
     77  mass_updates(
     78    CATEGORIES_TABLE,
     79    array(
     80      'primary' => array('id'),
     81      'update' => array_diff(array_keys($versos_cat), array('id'))
     82      ),
     83    array($versos_cat)
     84    );
     85   
     86  $conf['back2front']['versos_cat'] = $versos_cat['id'];
     87  conf_update_param('back2front', serialize($conf['back2front']));
    4088}
    4189
    4290function picture_exists($id)
    4391{
    44   if (!preg_match('#([0-9]{1,})#', $id) OR $id == '0') return false;
     92  if (!preg_match('#([0-9]{1,})#', $id) || $id == '0') return false;
    4593 
    4694  $query = "SELECT id FROM ".IMAGES_TABLE." WHERE id = ".$id.";";
Note: See TracChangeset for help on using the changeset viewer.