source: extensions/AdditionalPages/admin/upgrade_from_21.php @ 9270

Last change on this file since 9270 was 9270, checked in by patdenice, 10 years ago

Additional pages can now be standalone

File size: 2.4 KB
Line 
1<?php
2
3if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
4
5global $prefixeTable, $conf;
6
7$query = 'ALTER TABLE ' . $prefixeTable . 'additionalpages
8CHANGE `id` `id` SMALLINT( 5 ) UNSIGNED NOT NULL AUTO_INCREMENT ,
9CHANGE `pos` `pos` SMALLINT( 5 ) NULL DEFAULT NULL ,
10CHANGE `lang` `lang` VARCHAR( 255 ) NULL DEFAULT NULL ,
11CHANGE `text` `content` LONGTEXT NOT NULL ,
12ADD `users` VARCHAR( 255 ) NULL DEFAULT NULL ,
13ADD `groups` VARCHAR( 255 ) NULL DEFAULT NULL ,
14ADD `permalink` VARCHAR( 64 ) NULL DEFAULT NULL ,
15ADD `standalone` ENUM( "true", "false" ) NOT NULL DEFAULT "false";';
16pwg_query($query);
17
18$query = '
19SELECT id, pos, title, lang
20FROM '.$prefixeTable.'additionalpages
21ORDER BY pos ASC, id ASC
22;';
23$result = pwg_query($query);
24while ($row = mysql_fetch_assoc($result))
25{
26  $title = $row['title'];
27  $authorized_users = 'NULL';
28  $authorized_groups = 'NULL';
29
30  if (strpos($title , '/user_id='))
31  {
32    $array = explode('/user_id=' , $title);
33    $title = $array[0];
34    $authorized_users = '"'.$array[1].'"';
35  }
36  if (strpos($title , '/group_id='))
37  {
38    $array = explode('/group_id=' , $title);
39    $title = $array[0];
40    $authorized_groups = '"'.$array[1].'"';
41  }
42
43  $position = $row['pos'];
44  if ($row['pos'] === '0')
45    $position = '-1';
46  elseif (empty($row['pos']))
47    $position = '0';
48
49  $language = $row['lang'] != 'ALL' ? '"'.$row['lang'].'"' : 'NULL';
50
51  $query = '
52UPDATE '.$prefixeTable.'additionalpages
53SET title = "'.addslashes($title).'",
54    pos = '.$position.',
55    lang = '.$language.',
56    users = '.$authorized_users.',
57    groups = '.$authorized_groups.'
58WHERE id = '.$row['id'].'
59;';
60  pwg_query($query);
61}
62
63$old_conf = explode ("," , $conf['additional_pages']);
64
65$new_conf = array(
66  'show_home' => @($old_conf[2] == 'on'),
67  'group_perm' => @($old_conf[6] == 'on'),
68  'user_perm' => @($old_conf[7] == 'on'),
69  'homepage' => null,
70  );
71
72$languages = explode('/', $old_conf[0]);
73$new_conf['languages'] = array();
74foreach($languages as $language)
75{
76  $array = explode(':', $language);
77  if (!isset($array[1])) $new_conf['languages']['default'] = $array[0];
78  else $new_conf['languages'][$array[0]] = $array[1];
79}
80
81$conf['additional_pages'] = $new_conf;
82
83$query = '
84UPDATE '.CONFIG_TABLE.'
85SET value = "'.addslashes(serialize($new_conf)).'"
86WHERE param = "additional_pages"
87;';
88pwg_query($query);
89
90?>
Note: See TracBrowser for help on using the repository browser.