diff options
Diffstat (limited to 'modules/profile')
-rw-r--r-- | modules/profile/profile.admin.inc | 22 | ||||
-rw-r--r-- | modules/profile/profile.install | 16 | ||||
-rw-r--r-- | modules/profile/profile.module | 22 | ||||
-rw-r--r-- | modules/profile/profile.pages.inc | 12 | ||||
-rw-r--r-- | modules/profile/profile.test | 2 |
5 files changed, 42 insertions, 32 deletions
diff --git a/modules/profile/profile.admin.inc b/modules/profile/profile.admin.inc index 16f5860e4..3e154fb83 100644 --- a/modules/profile/profile.admin.inc +++ b/modules/profile/profile.admin.inc @@ -13,7 +13,7 @@ * @see profile_admin_overview_submit() */ function profile_admin_overview() { - $result = db_query('SELECT title, name, type, category, fid, weight FROM {profile_fields} ORDER BY category, weight'); + $result = db_query('SELECT title, name, type, category, fid, weight FROM {profile_field} ORDER BY category, weight'); $form = array(); $categories = array(); @@ -74,7 +74,7 @@ function profile_admin_overview_submit($form, &$form_state) { $weight = $form_state['values'][$fid]['weight']; $category = $form_state['values'][$fid]['category']; if ($weight != $form[$fid]['weight']['#default_value'] || $category != $form[$fid]['category']['#default_value']) { - db_query("UPDATE {profile_fields} SET weight = %d, category = '%s' WHERE fid = %d", $weight, $category, $fid); + db_query("UPDATE {profile_field} SET weight = %d, category = '%s' WHERE fid = %d", $weight, $category, $fid); } } } @@ -169,7 +169,7 @@ function profile_field_form(&$form_state, $arg = NULL) { if (is_numeric($arg)) { $fid = $arg; - $edit = db_fetch_array(db_query('SELECT * FROM {profile_fields} WHERE fid = %d', $fid)); + $edit = db_fetch_array(db_query('SELECT * FROM {profile_field} WHERE fid = %d', $fid)); if (!$edit) { drupal_not_found(); @@ -314,10 +314,10 @@ function profile_field_form_validate($form, &$form_state) { $query_suffix = ' AND fid != %d'; } - if (db_result(db_query("SELECT fid FROM {profile_fields} WHERE title = '%s' AND category = '%s'" . $query_suffix, $args1))) { + if (db_result(db_query("SELECT fid FROM {profile_field} WHERE title = '%s' AND category = '%s'" . $query_suffix, $args1))) { form_set_error('title', t('The specified title is already in use.')); } - if (db_result(db_query("SELECT fid FROM {profile_fields} WHERE name = '%s'" . $query_suffix, $args2))) { + if (db_result(db_query("SELECT fid FROM {profile_field} WHERE name = '%s'" . $query_suffix, $args2))) { form_set_error('name', t('The specified name is already in use.')); } if ($form_state['values']['visibility'] == PROFILE_HIDDEN) { @@ -341,13 +341,13 @@ function profile_field_form_submit($form, &$form_state) { $form_state['values']['page'] = ''; } if (!isset($form_state['values']['fid'])) { - db_query("INSERT INTO {profile_fields} (title, name, explanation, category, type, weight, required, register, visibility, autocomplete, options, page) VALUES ('%s', '%s', '%s', '%s', '%s', %d, %d, %d, %d, %d, '%s', '%s')", $form_state['values']['title'], $form_state['values']['name'], $form_state['values']['explanation'], $form_state['values']['category'], $form_state['values']['type'], $form_state['values']['weight'], $form_state['values']['required'], $form_state['values']['register'], $form_state['values']['visibility'], $form_state['values']['autocomplete'], $form_state['values']['options'], $form_state['values']['page']); + db_query("INSERT INTO {profile_field} (title, name, explanation, category, type, weight, required, register, visibility, autocomplete, options, page) VALUES ('%s', '%s', '%s', '%s', '%s', %d, %d, %d, %d, %d, '%s', '%s')", $form_state['values']['title'], $form_state['values']['name'], $form_state['values']['explanation'], $form_state['values']['category'], $form_state['values']['type'], $form_state['values']['weight'], $form_state['values']['required'], $form_state['values']['register'], $form_state['values']['visibility'], $form_state['values']['autocomplete'], $form_state['values']['options'], $form_state['values']['page']); drupal_set_message(t('The field has been created.')); watchdog('profile', 'Profile field %field added under category %category.', array('%field' => $form_state['values']['title'], '%category' => $form_state['values']['category']), WATCHDOG_NOTICE, l(t('view'), 'admin/user/profile')); } else { - db_query("UPDATE {profile_fields} SET title = '%s', name = '%s', explanation = '%s', category = '%s', weight = %d, required = %d, register = %d, visibility = %d, autocomplete = %d, options = '%s', page = '%s' WHERE fid = %d", $form_state['values']['title'], $form_state['values']['name'], $form_state['values']['explanation'], $form_state['values']['category'], $form_state['values']['weight'], $form_state['values']['required'], $form_state['values']['register'], $form_state['values']['visibility'], $form_state['values']['autocomplete'], $form_state['values']['options'], $form_state['values']['page'], $form_state['values']['fid']); + db_query("UPDATE {profile_field} SET title = '%s', name = '%s', explanation = '%s', category = '%s', weight = %d, required = %d, register = %d, visibility = %d, autocomplete = %d, options = '%s', page = '%s' WHERE fid = %d", $form_state['values']['title'], $form_state['values']['name'], $form_state['values']['explanation'], $form_state['values']['category'], $form_state['values']['weight'], $form_state['values']['required'], $form_state['values']['register'], $form_state['values']['visibility'], $form_state['values']['autocomplete'], $form_state['values']['options'], $form_state['values']['page'], $form_state['values']['fid']); drupal_set_message(t('The field has been updated.')); } @@ -362,7 +362,7 @@ function profile_field_form_submit($form, &$form_state) { * Menu callback; deletes a field from all user profiles. */ function profile_field_delete(&$form_state, $fid) { - $field = db_fetch_object(db_query("SELECT title FROM {profile_fields} WHERE fid = %d", $fid)); + $field = db_fetch_object(db_query("SELECT title FROM {profile_field} WHERE fid = %d", $fid)); if (!$field) { drupal_not_found(); return; @@ -380,8 +380,8 @@ function profile_field_delete(&$form_state, $fid) { * Process a field delete form submission. */ function profile_field_delete_submit($form, &$form_state) { - db_query('DELETE FROM {profile_fields} WHERE fid = %d', $form_state['values']['fid']); - db_query('DELETE FROM {profile_values} WHERE fid = %d', $form_state['values']['fid']); + db_query('DELETE FROM {profile_field} WHERE fid = %d', $form_state['values']['fid']); + db_query('DELETE FROM {profile_value} WHERE fid = %d', $form_state['values']['fid']); cache_clear_all(); @@ -397,7 +397,7 @@ function profile_field_delete_submit($form, &$form_state) { */ function profile_admin_settings_autocomplete($string) { $matches = array(); - $result = db_query_range("SELECT category FROM {profile_fields} WHERE LOWER(category) LIKE LOWER(:category)", array(':category' => $string .'%'), 0, 10); + $result = db_query_range("SELECT category FROM {profile_field} WHERE LOWER(category) LIKE LOWER(:category)", array(':category' => $string .'%'), 0, 10); while ($data = db_fetch_object($result)) { $matches[$data->category] = check_plain($data->category); } diff --git a/modules/profile/profile.install b/modules/profile/profile.install index e21d8a11a..a4c1fd24f 100644 --- a/modules/profile/profile.install +++ b/modules/profile/profile.install @@ -23,7 +23,7 @@ function profile_uninstall() { * Implementation of hook_schema(). */ function profile_schema() { - $schema['profile_fields'] = array( + $schema['profile_field'] = array( 'description' => 'Stores profile field information.', 'fields' => array( 'fid' => array( @@ -117,7 +117,7 @@ function profile_schema() { 'primary key' => array('fid'), ); - $schema['profile_values'] = array( + $schema['profile_value'] = array( 'description' => 'Stores values for profile fields.', 'fields' => array( 'fid' => array( @@ -125,7 +125,7 @@ function profile_schema() { 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0, - 'description' => 'The {profile_fields}.fid of the field.', + 'description' => 'The {profile_field}.fid of the field.', ), 'uid' => array( 'type' => 'int', @@ -148,3 +148,13 @@ function profile_schema() { return $schema; } + +/** + * Rename {profile_fields} table to {profile_field} and {profile_values} to {profile_value}. + */ +function profile_update_7001() { + $ret = array(); + db_rename_table($ret, 'profile_fields', 'profile_field'); + db_rename_table($ret, 'profile_values', 'profile_value'); + return $ret; +} diff --git a/modules/profile/profile.module b/modules/profile/profile.module index 9352f4b3b..6ecd27c67 100644 --- a/modules/profile/profile.module +++ b/modules/profile/profile.module @@ -138,7 +138,7 @@ function profile_block($op = 'list', $delta = '', $edit = array()) { elseif ($op == 'configure') { // Compile a list of fields to show $fields = array(); - $result = db_query('SELECT name, title, weight, visibility FROM {profile_fields} WHERE visibility IN (%d, %d) ORDER BY weight', PROFILE_PUBLIC, PROFILE_PUBLIC_LISTINGS); + $result = db_query('SELECT name, title, weight, visibility FROM {profile_field} WHERE visibility IN (%d, %d) ORDER BY weight', PROFILE_PUBLIC, PROFILE_PUBLIC_LISTINGS); while ($record = db_fetch_object($result)) { $fields[$record->name] = check_plain($record->title); } @@ -165,7 +165,7 @@ function profile_block($op = 'list', $delta = '', $edit = array()) { if ($use_fields = variable_get('profile_block_author_fields', array())) { // Compile a list of fields to show. $fields = array(); - $result = db_query('SELECT name, title, type, visibility, weight FROM {profile_fields} WHERE visibility IN (%d, %d) ORDER BY weight', PROFILE_PUBLIC, PROFILE_PUBLIC_LISTINGS); + $result = db_query('SELECT name, title, type, visibility, weight FROM {profile_field} WHERE visibility IN (%d, %d) ORDER BY weight', PROFILE_PUBLIC, PROFILE_PUBLIC_LISTINGS); while ($record = db_fetch_object($result)) { // Ensure that field is displayed only if it is among the defined block fields and, if it is private, the user has appropriate permissions. if (isset($use_fields[$record->name]) && $use_fields[$record->name]) { @@ -253,11 +253,11 @@ function profile_user_categories(&$edit, &$user, $category = NULL) { * Implementation of hook_user_delete(). */ function profile_user_delete(&$edit, &$user, $category = NULL) { - db_query('DELETE FROM {profile_values} WHERE uid = %d', $user->uid); + db_query('DELETE FROM {profile_value} WHERE uid = %d', $user->uid); } function profile_load_profile(&$user) { - $result = db_query('SELECT f.name, f.type, v.value FROM {profile_fields} f INNER JOIN {profile_values} v ON f.fid = v.fid WHERE uid = %d', $user->uid); + $result = db_query('SELECT f.name, f.type, v.value FROM {profile_field} f INNER JOIN {profile_value} v ON f.fid = v.fid WHERE uid = %d', $user->uid); while ($field = db_fetch_object($result)) { if (empty($user->{$field->name})) { $user->{$field->name} = _profile_field_serialize($field->type) ? unserialize($field->value) : $field->value; @@ -271,8 +271,8 @@ function profile_save_profile(&$edit, &$user, $category, $register = FALSE) { if (_profile_field_serialize($field->type)) { $edit[$field->name] = serialize($edit[$field->name]); } - db_query("DELETE FROM {profile_values} WHERE fid = %d AND uid = %d", $field->fid, $user->uid); - db_query("INSERT INTO {profile_values} (fid, uid, value) VALUES (%d, %d, '%s')", $field->fid, $user->uid, $edit[$field->name]); + db_query("DELETE FROM {profile_value} WHERE fid = %d AND uid = %d", $field->fid, $user->uid); + db_query("INSERT INTO {profile_value} (fid, uid, value) VALUES (%d, %d, '%s')", $field->fid, $user->uid, $edit[$field->name]); // Mark field as handled (prevents saving to user->data). $edit[$field->name] = NULL; } @@ -331,10 +331,10 @@ function profile_view_profile(&$user) { // Show private fields to administrators and people viewing their own account. if (user_access('administer users') || $GLOBALS['user']->uid == $user->uid) { - $result = db_query('SELECT * FROM {profile_fields} WHERE visibility != %d ORDER BY category, weight', PROFILE_HIDDEN); + $result = db_query('SELECT * FROM {profile_field} WHERE visibility != %d ORDER BY category, weight', PROFILE_HIDDEN); } else { - $result = db_query('SELECT * FROM {profile_fields} WHERE visibility != %d AND visibility != %d ORDER BY category, weight', PROFILE_PRIVATE, PROFILE_HIDDEN); + $result = db_query('SELECT * FROM {profile_field} WHERE visibility != %d AND visibility != %d ORDER BY category, weight', PROFILE_PRIVATE, PROFILE_HIDDEN); } $fields = array(); @@ -480,7 +480,7 @@ function profile_validate_profile($edit, $category) { } function profile_categories() { - $result = db_query("SELECT DISTINCT(category) FROM {profile_fields}"); + $result = db_query("SELECT DISTINCT(category) FROM {profile_field}"); $data = array(); while ($category = db_fetch_object($result)) { $data[] = array( @@ -502,7 +502,7 @@ function profile_category_access($account, $category) { return TRUE; } else { - return user_edit_access($account) && db_result(db_query("SELECT COUNT(*) FROM {profile_fields} WHERE category = '%s' AND visibility <> %d", $category, PROFILE_HIDDEN)); + return user_edit_access($account) && db_result(db_query("SELECT COUNT(*) FROM {profile_field} WHERE category = '%s' AND visibility <> %d", $category, PROFILE_HIDDEN)); } } @@ -589,7 +589,7 @@ function _profile_field_serialize($type = NULL) { function _profile_get_fields($category, $register = FALSE) { $args = array(); - $sql = 'SELECT * FROM {profile_fields} WHERE '; + $sql = 'SELECT * FROM {profile_field} WHERE '; $filters = array(); if ($register) { $filters[] = 'register = 1'; diff --git a/modules/profile/profile.pages.inc b/modules/profile/profile.pages.inc index fa8dbef31..9cb761a28 100644 --- a/modules/profile/profile.pages.inc +++ b/modules/profile/profile.pages.inc @@ -13,7 +13,7 @@ function profile_browse() { // Ensure that the path is converted to 3 levels always. list(, $name, $value) = array_pad(explode('/', $_GET['q'], 3), 3, ''); - $field = db_fetch_object(db_query("SELECT DISTINCT(fid), type, title, page, visibility FROM {profile_fields} WHERE name = '%s'", $name)); + $field = db_fetch_object(db_query("SELECT DISTINCT(fid), type, title, page, visibility FROM {profile_field} WHERE name = '%s'", $name)); if ($name && $field->fid) { // Only allow browsing of fields that have a page title set. @@ -29,7 +29,7 @@ function profile_browse() { // Compile a list of fields to show. $fields = array(); - $result = db_query('SELECT name, title, type, weight, page FROM {profile_fields} WHERE fid != %d AND visibility = %d ORDER BY weight', $field->fid, PROFILE_PUBLIC_LISTINGS); + $result = db_query('SELECT name, title, type, weight, page FROM {profile_field} WHERE fid != %d AND visibility = %d ORDER BY weight', $field->fid, PROFILE_PUBLIC_LISTINGS); while ($record = db_fetch_object($result)) { $fields[] = $record; } @@ -55,7 +55,7 @@ function profile_browse() { } // Extract the affected users: - $result = pager_query("SELECT u.uid, u.access FROM {users} u INNER JOIN {profile_values} v ON u.uid = v.uid WHERE v.fid = %d AND $query AND u.access != 0 AND u.status != 0 ORDER BY u.access DESC", 20, 0, NULL, $arguments); + $result = pager_query("SELECT u.uid, u.access FROM {users} u INNER JOIN {profile_value} v ON u.uid = v.uid WHERE v.fid = %d AND $query AND u.access != 0 AND u.status != 0 ORDER BY u.access DESC", 20, 0, NULL, $arguments); $content = ''; while ($account = db_fetch_object($result)) { @@ -82,7 +82,7 @@ function profile_browse() { else { // Compile a list of fields to show. $fields = array(); - $result = db_query('SELECT name, title, type, weight, page, visibility FROM {profile_fields} WHERE visibility = %d ORDER BY category, weight', PROFILE_PUBLIC_LISTINGS); + $result = db_query('SELECT name, title, type, weight, page, visibility FROM {profile_field} WHERE visibility = %d ORDER BY category, weight', PROFILE_PUBLIC_LISTINGS); while ($record = db_fetch_object($result)) { $fields[] = $record; } @@ -109,8 +109,8 @@ function profile_browse() { */ function profile_autocomplete($field, $string) { $matches = array(); - if (db_result(db_query("SELECT COUNT(*) FROM {profile_fields} WHERE fid = %d AND autocomplete = 1", $field))) { - $result = db_query_range("SELECT value FROM {profile_values} WHERE fid = :fid AND LOWER(value) LIKE LOWER(:value) GROUP BY value ORDER BY value ASC", array( + if (db_result(db_query("SELECT COUNT(*) FROM {profile_field} WHERE fid = %d AND autocomplete = 1", $field))) { + $result = db_query_range("SELECT value FROM {profile_value} WHERE fid = :fid AND LOWER(value) LIKE LOWER(:value) GROUP BY value ORDER BY value ASC", array( ':fid' => $field, ':value' => $string .'%', ), 0, 10); diff --git a/modules/profile/profile.test b/modules/profile/profile.test index 4ffa92130..7dd22c043 100644 --- a/modules/profile/profile.test +++ b/modules/profile/profile.test @@ -37,7 +37,7 @@ class ProfileTestCase extends DrupalWebTestCase { $edit['explanation'] = $this->randomName(50); $this->drupalPost('admin/user/profile/add/' . $type, $edit, t('Save field')); - $fid = db_result(db_query("SELECT fid FROM {profile_fields} WHERE title = '%s'", $title)); + $fid = db_result(db_query("SELECT fid FROM {profile_field} WHERE title = '%s'", $title)); $this->assertTrue($fid, t('New Profile field has been entered in the database')); // Check that the new field is appearing on the user edit form. |