XOOPS 2.5.6  Final
 All Classes Namespaces Files Functions Variables Pages
update.php
Go to the documentation of this file.
1 <?php
20 function xoops_module_update_profile(&$module, $oldversion = null)
21 {
22  if ( $oldversion < 162 ) {
23  $GLOBALS['xoopsDB']->queryF("UPDATE `" . $GLOBALS['xoopsDB']->prefix("profile_field") . " SET field_valuetype=2 WHERE field_name=umode");
24  }
25 
26  if ( $oldversion < 100 ) {
27 
28  // Drop old category table
29  $sql = "DROP TABLE " . $GLOBALS['xoopsDB']->prefix("profile_category");
30  $GLOBALS['xoopsDB']->queryF($sql);
31 
32  // Drop old field-category link table
33  $sql = "DROP TABLE " . $GLOBALS['xoopsDB']->prefix("profile_fieldcategory");
34  $GLOBALS['xoopsDB']->queryF($sql);
35 
36  // Create new tables for new profile module
37  $GLOBALS['xoopsDB']->queryFromFile(XOOPS_ROOT_PATH . "/modules/" . $module->getVar('dirname', 'n') . "/sql/mysql.sql");
38 
39  include_once dirname(__FILE__) . "/install.php";
41  $goupperm_handler =& xoops_getHandler("groupperm");
42 
43  $field_handler =& xoops_getModuleHandler('field', $module->getVar('dirname', 'n') );
44  $skip_fields = $field_handler->getUserVars();
45  $skip_fields[] = 'newemail';
46  $skip_fields[] = 'pm_link';
47  $sql = "SELECT * FROM `" . $GLOBALS['xoopsDB']->prefix("user_profile_field") . "` WHERE `field_name` NOT IN ('" . implode("', '", $skip_fields) . "')";
48  $result = $GLOBALS['xoopsDB']->query($sql);
49  $fields = array();
50  while ($myrow = $GLOBALS['xoopsDB']->fetchArray($result) ) {
51  $fields[] = $myrow['field_name'];
52  $object =& $field_handler->create();
53  $object->setVars($myrow, true);
54  $object->setVar('cat_id', 1);
55  if ( !empty($myrow['field_register']) ) {
56  $object->setVar('step_id', 2);
57  }
58  if ( !empty($myrow['field_options']) ) {
59  $object->setVar('field_options', unserialize($myrow['field_options']) );
60  }
61  $field_handler->insert($object, true);
62 
63  $gperm_itemid = $object->getVar('field_id');
64  $sql = "UPDATE " . $GLOBALS['xoopsDB']->prefix("group_permission") . " SET gperm_itemid = " . $gperm_itemid .
65  " WHERE gperm_itemid = " . $myrow['fieldid'] .
66  " AND gperm_modid = " . $module->getVar('mid') .
67  " AND gperm_name IN ('profile_edit', 'profile_search')";
68  $GLOBALS['xoopsDB']->queryF($sql);
69 
70  $groups_visible = $goupperm_handler->getGroupIds("profile_visible", $myrow['fieldid'], $module->getVar('mid') );
71  $groups_show = $goupperm_handler->getGroupIds("profile_show", $myrow['fieldid'], $module->getVar('mid') );
72  foreach ($groups_visible as $ugid ) {
73  foreach ($groups_show as $pgid ) {
74  $sql = "INSERT INTO " . $GLOBALS['xoopsDB']->prefix("profile_visibility") .
75  " (field_id, user_group, profile_group) " .
76  " VALUES " .
77  " ({$gperm_itemid}, {$ugid}, {$pgid})";
78  $GLOBALS['xoopsDB']->queryF($sql);
79  }
80  }
81 
82  //profile_install_setPermissions($object->getVar('field_id'), $module->getVar('mid'), $canedit, $visible);
83  unset($object);
84  }
85 
86  // Copy data from profile table
87  foreach ($fields as $field ) {
88  $GLOBALS['xoopsDB']->queryF("UPDATE `" . $GLOBALS['xoopsDB']->prefix("profile_profile") . "` u, `" . $GLOBALS['xoopsDB']->prefix("user_profile") . "` p SET u.{$field} = p.{$field} WHERE u.profile_id=p.profileid");
89  }
90 
91  // Drop old profile table
92  $sql = "DROP TABLE " . $GLOBALS['xoopsDB']->prefix("user_profile");
93  $GLOBALS['xoopsDB']->queryF($sql);
94 
95  // Drop old field module
96  $sql = "DROP TABLE " . $GLOBALS['xoopsDB']->prefix("user_profile_field");
97  $GLOBALS['xoopsDB']->queryF($sql);
98 
99  // Remove not used items
100  $sql = "DELETE FROM " . $GLOBALS['xoopsDB']->prefix("group_permission") .
101  " WHERE `gperm_modid` = " . $module->getVar('mid') . " AND `gperm_name` IN ('profile_show', 'profile_visible')";
102  $GLOBALS['xoopsDB']->queryF($sql);
103  }
104 
105  if ($oldversion < 162) {
106  $GLOBALS['xoopsDB']->queryF("UPDATE `" . $GLOBALS['xoopsDB']->prefix("profile_field") . "` SET `field_valuetype`=1 WHERE `field_name`='umode'");
107  }
108 
109  $profile_handler =& xoops_getModuleHandler("profile", $module->getVar('dirname', 'n') );
110  $profile_handler->cleanOrphan($GLOBALS['xoopsDB']->prefix("users"), "uid", "profile_id");
111  $field_handler =& xoops_getModuleHandler('field', $module->getVar('dirname', 'n') );
112  $user_fields = $field_handler->getUserVars();
113  $criteria = new Criteria("field_name", "('" . implode("', '", $user_fields) . "')", "IN");
114  $field_handler->updateAll("field_config", 0, $criteria);
115 
116  return true;
117 }
118 ?>