Mercurial > defr > drupal > og_statistics
diff og_statistics.admin.inc @ 2:48f07e7acaca
OG Stats 1.0-rc2
author | Franck Deroche <franck@defr.org> |
---|---|
date | Tue, 24 Nov 2009 14:27:37 +0100 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/og_statistics.admin.inc Tue Nov 24 14:27:37 2009 +0100 @@ -0,0 +1,45 @@ +<?php +// $Id: og_statistics.admin.inc,v 1.1.2.1 2009/09/08 20:42:56 dereine Exp $ +/** + * @file + * Admin settings for og_statistics module. + */ + +function og_statistics_settings() { + $form['rebuild'] = array( + '#type' => 'submit', + '#value' => t('Rebuild og_statistics') + ); + + return $form; +} + +function og_statistics_settings_submit(&$form, &$form_state) { + // get all group nodes + $types = og_get_types('group'); + $placeholders = db_placeholders($types, 'varchar'); + $result = db_query("SELECT nid FROM {node} WHERE type IN($placeholders)", $types); + while ($item = db_fetch_object($result)) { + $nodes[$item->nid] = $item->nid; + } + $counter = 0; + foreach ($nodes as $nid) { + $counter ++; + $array[] = $nid; + if (($counter % 20) == 1) { + $operations[] = array('og_statistcs_recalc', array($array)); + $array = array(); + } + } + $operations[] = array('og_statistcs_recalc', array($array)); + // Execute the batch progress + $batch = array( + 'operations' => $operations, + 'title' => 'Generating statistics', + 'init_message' => 'Loading group nodes', + 'error_message' => 'An unrecoverable error has occurred. You can find the error message below. It is advised to copy it to the clipboard for reference.', + 'finished' => 'og_statistcs_settings_finished', + ); + batch_set($batch); + batch_process('admin/settings/og_statistics'); +}