1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10:
11:
12: 13: 14: 15: 16: 17: 18: 19: 20:
21:
22: 23: 24: 25: 26:
27: function xoops_module_update_profile(&$module, $oldversion = null)
28: {
29: global $xoopsDB;
30: $xoops = Xoops::getInstance();
31:
32: if ($oldversion < 162) {
33: $xoopsDB->queryF("UPDATE `" . $xoopsDB->prefix("profile_field") . " SET field_valuetype=2 WHERE field_name=umode");
34: }
35:
36: if ($oldversion < 100) {
37:
38:
39: $sql = "DROP TABLE " . $xoopsDB->prefix("profile_category");
40: $xoopsDB->queryF($sql);
41:
42:
43: $sql = "DROP TABLE " . $xoopsDB->prefix("profile_fieldcategory");
44: $xoopsDB->queryF($sql);
45:
46:
47: $xoopsDB->queryFromFile(\XoopsBaseConfig::get('root-path') . "/modules/" . $module->getVar('dirname', 'n') . "/sql/mysql.sql");
48:
49: include_once __DIR__ . "/install.php";
50: xoops_module_install_profile($module);
51: $goupperm_handler = $xoops->getHandlerGroupPermission();
52:
53:
54: $field_handler = $xoops->getModuleHandler('field', $module->getVar('dirname', 'n'));
55: $skip_fields = $field_handler->getUserVars();
56: $skip_fields[] = 'newemail';
57: $skip_fields[] = 'pm_link';
58: $sql = "SELECT * FROM `" . $xoopsDB->prefix("user_profile_field") . "` WHERE `field_name` NOT IN ('" . implode("', '", $skip_fields) . "')";
59: $result = $xoopsDB->query($sql);
60: $fields = array();
61: while ($myrow = $xoopsDB->fetchArray($result)) {
62: $fields[] = $myrow['field_name'];
63: $object = $field_handler->create();
64: $object->setVars($myrow);
65: $object->setVar('cat_id', 1);
66: if (!empty($myrow['field_register'])) {
67: $object->setVar('step_id', 2);
68: }
69: if (!empty($myrow['field_options'])) {
70: $object->setVar('field_options', unserialize($myrow['field_options']));
71: }
72: $field_handler->insert($object, true);
73:
74: $gperm_itemid = $object->getVar('field_id');
75: $sql = "UPDATE " . $xoopsDB->prefix("system_permission") . " SET gperm_itemid = " . $gperm_itemid . " WHERE gperm_itemid = " . $myrow['fieldid'] . " AND gperm_modid = " . $module->getVar('mid') . " AND gperm_name IN ('profile_edit', 'profile_search')";
76: $xoopsDB->queryF($sql);
77:
78: $groups_visible = $goupperm_handler->getGroupIds("profile_visible", $myrow['fieldid'], $module->getVar('mid'));
79: $groups_show = $goupperm_handler->getGroupIds("profile_show", $myrow['fieldid'], $module->getVar('mid'));
80: foreach ($groups_visible as $ugid) {
81: foreach ($groups_show as $pgid) {
82: $sql = "INSERT INTO " . $xoopsDB->prefix("profile_visibility") . " (field_id, user_group, profile_group) " . " VALUES " . " ({$gperm_itemid}, {$ugid}, {$pgid})";
83: $xoopsDB->queryF($sql);
84: }
85: }
86:
87:
88: unset($object);
89: }
90:
91:
92: foreach ($fields as $field) {
93: $xoopsDB->queryF("UPDATE `" . $xoopsDB->prefix("profile_profile") . "` u, `" . $xoopsDB->prefix("user_profile") . "` p SET u.{$field} = p.{$field} WHERE u.profile_id=p.profileid");
94: }
95:
96:
97: $sql = "DROP TABLE " . $xoopsDB->prefix("user_profile");
98: $xoopsDB->queryF($sql);
99:
100:
101: $sql = "DROP TABLE " . $xoopsDB->prefix("user_profile_field");
102: $xoopsDB->queryF($sql);
103:
104:
105: $sql = "DELETE FROM " . $xoopsDB->prefix("system_permission") . " WHERE `gperm_modid` = " . $module->getVar('mid') . " AND `gperm_name` IN ('profile_show', 'profile_visible')";
106: $xoopsDB->queryF($sql);
107: }
108:
109: $profile_handler = $xoops->getModuleHandler("profile", $module->getVar('dirname', 'n'));
110: $profile_handler->cleanOrphan($xoopsDB->prefix("system_user"), "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: