Commit ec7f3e5f authored by generalredneck's avatar generalredneck

Porting Batch Index rebuilding to Drupal 7

There were some DB calls inside the batch process that needed to be updated. In addition, the menu item was dated to Drupal 6. Updated it to comply with the way Drupal 7 puts things in "Configuration".
parent 03f6bab6
......@@ -47,16 +47,24 @@ function views_natural_sort_rebuild_index(&$context) {
// Initialize our context.
if (!isset($sandbox['max'])) {
$sandbox['progress'] = 0;
$sandbox['max'] = db_result(db_query('SELECT MAX(nid) FROM {node}'));
$sandbox['total'] = db_result(db_query('SELECT COUNT(nid) FROM {node} WHERE nid <= %d', $sandbox['max']));
$sandbox['max'] = db_query('SELECT MAX(nid) FROM {node}')->fetchField();
$sandbox['total'] = db_query(
'SELECT COUNT(nid) FROM {node} WHERE nid <= :max',
array('max' => $sandbox['max'])
)->fetchField();
$sandbox['current'] = 0;
$context['results']['nodes'] = 0;
}
$results = db_query_range('SELECT nid, title FROM {node} WHERE nid > %d AND nid <= %d', $sandbox['current'], $sandbox['max'], 0, 10);
$results = db_query_range(
'SELECT nid, title FROM {node} WHERE nid > :current AND nid <= :max',
0,
10,
array('current' => $sandbox['current'], 'max' => $sandbox['max'])
);
$title = '';
while($row = db_fetch_object($results)) {
foreach ($results as $row) {
_views_natural_sort_store_node($row);
++$sandbox['progress'];
$sandbox['current'] = $row->nid;
......
......@@ -23,18 +23,25 @@
* Implementation of hook_menu().
*/
function views_natural_sort_menu() {
//
$items = array();
$items['admin/settings/views_natural_sort'] = array(
$items['admin/config/views_natural_sort'] = array(
'title' => 'Views Natural Sort',
'description' => 'Provides options for what should be indexed for sorting.',
'description' => 'Configuration and settings for natural sorting.',
'page callback' => 'system_admin_menu_block_page',
'access arguments' => array('administer site configuration'),
'file' => 'system.admin.inc',
'file path' => drupal_get_path('module', 'system'),
);
$items['admin/config/views_natural_sort/rebuild'] = array(
'title' => 'Rebuild Search Index',
'description' => 'Rebuild Views Natural Sort\'s search index',
'page callback' => 'drupal_get_form',
'page arguments' => array('views_natural_sort_settings_form'),
'access callback' => 'user_access',
'access arguments' => array('administer views'),
'file' => 'views_natural_sort.admin.inc',
'type' => MENU_NORMAL_ITEM
'type' => MENU_NORMAL_ITEM,
);
return $items;
......@@ -76,18 +83,17 @@ function views_natural_sort_node_update($node) {
* MergeQuery::STATUS_UPDATE or MergeQuery::STATUS_INSERT
*/
function _views_natural_sort_store_node($node) {
// Try to update. On fail, try inserting.
return db_merge('views_natural_sort')
->key( array(
->key(array(
'nid' => $node->nid,
'field'=> 'title'
))
->fields( array(
))
->fields(array(
'nid' => $node->nid,
'field' => 'title',
'content' => _views_natural_sort_filter_content($node->title)
))
->execute();
->execute();
}
/**
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment