summaryrefslogtreecommitdiffstats
path: root/views_natural_sort.install
blob: 296b39ea6ce0016d273184606a1947d35cac997f (plain)
1
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
<?php

/**
 * @file
 */

/**
 * Implementation of hook_schema().
 */
function views_natural_sort_schema() {

  // Contains relations between two users.
  $schema['views_natural_sort'] = array(
    'description' => t('Compressed titles for natural sorting.'),
    'fields' => array(
      'eid' => array(
        'description' => t('Entity id'),
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'entity_type' => array(
        'description' => t('Entity Type'),
        'type' => 'varchar',
        'length' => 128,
        'not null' => TRUE,
        'default' => 'node',
      ),
      'field' => array(
        'description' => t('The field name. This will be title or some cck text field, etc.'),
        'type' => 'varchar',
        'length' => 32,
        'not null' => TRUE,
        'default' => '',
      ),
      'delta' => array(
        'description' => t('The sequence number for this data item, used for multi-value fields'),
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'content' => array(
        'description' => t('Filtered content used for sorting.'),
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ),
    ),
    'primary key' => array('eid', 'entity_type', 'field', 'delta'),
  );

  return $schema;
}

/**
 * Implementation of hook_install().
 */
function views_natural_sort_install() {
  variable_set(
    'views_natural_sort_beginning_words_remove',
    array(
      t('The'),
      t('A'),
      t('An'),
      t('La'),
      t('Le'),
      t('Il'),
    )
  );
  variable_set(
    'views_natural_sort_words_remove',
    array(
      t('and'),
      t('or'),
      t('of'),
    )
  );
  variable_set('views_natural_sort_symbols_remove', "#\"'\\()[]");
  variable_set('views_natural_sort_days_of_the_week_enabled', FALSE);
  variable_set('views_natural_sort_rebuild_items_per_batch', 500);
}

/**
 * Implementation of hook_enable().
 */
function views_natural_sort_enable() {
  module_load_include('inc', 'views_natural_sort', 'views_natural_sort.admin');
  views_natural_sort_rebuild_index_submit();
}

/**
 * Implementation of hook_uninstall().
 */
function views_natural_sort_uninstall() {
  variable_del('views_natural_sort_beginning_words_remove');
  variable_del('views_natural_sort_words_remove');
  variable_del('views_natural_sort_symbols_remove');
  variable_del('views_natural_sort_days_of_the_week_enabled');
  variable_del('views_natural_sort_rebuild_items_per_batch');
}

/**
 * Impliments hook_update_N().
 *
 * Rebuild the sorting index after changes made for numerical data.
 */
function views_natural_sort_update_7001() {
  module_load_include('inc', 'views_natural_sort', 'views_natural_sort.admin');
  views_natural_sort_rebuild_index_submit();
}

/**
 * Impliments hook_update_N().
 *
 * Upgrade the 7.x-1.x table structure to the 7.x-2.x table structure.
 */
function views_natural_sort_update_7200() {
  db_drop_primary_key('views_natural_sort');
  db_add_field(
    'views_natural_sort',
    'entity_type',
    array(
      'description' => t('Entity Type'),
      'type' => 'varchar',
      'length' => 128,
      'not null' => TRUE,
      'default' => 'node',
    )
  );
  db_add_field(
    'views_natural_sort',
    'delta',
    array(
      'description' => t('The sequence number for this data item, used for multi-value fields'),
      'type' => 'int',
      'unsigned' => TRUE,
      'not null' => TRUE,
      'default' => 0,
    )
  );
  db_change_field(
    'views_natural_sort',
    'nid',
    'eid',
    array(
      'description' => t('Entity id'),
      'type' => 'int',
      'unsigned' => TRUE,
      'not null' => TRUE,
    ),
    array(
      'primary key' => array('eid', 'entity_type', 'field', 'delta'),
    )
  );
  module_load_include('inc', 'views_natural_sort', 'views_natural_sort.admin');
  views_natural_sort_rebuild_index_submit();
}

/**
 * Upgrading 1.x VNS views to 2.x VNS views.
 */
function views_natural_sort_update_7201() {
  foreach ($views as $view_name => $view) {
    foreach ($view->display as &$display) {
      if (!empty($display->display_options['sorts'])) {
        foreach ($display->display_options['sorts'] as &$sort) {
          if ($sort['table'] == 'views_natural_sort') {
            $sort['table'] = 'node';
            $sort['field'] = 'title';
            $sort['order'] = 'N' . $sort['order'];
            $view->save();
            drupal_set_message(t('Views Natural Sort Upgraded the view !name.', array('!name' => $view_name)), 'status');
          }
        }
      }
    }
  }
  cache_clear_all();
  return t('If you implement your views using Features, be sure to update the Featues that contain View Natural Sort Views immediatly after this upgrade and before the next revert.');
}