From e78d4261c296d20c3cebcd7e4e23431c04afa0a9 Mon Sep 17 00:00:00 2001 From: Carlo Landmeter Date: Tue, 26 Apr 2011 15:09:14 +0200 Subject: multiple changes add function: remove all apk nodes add function: format commit url, add commit title from aggregator if possible and use a tooltip modified/add apk fields to reflect new apk_tools --- apk_browser.module | 156 ++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 150 insertions(+), 6 deletions(-) (limited to 'apk_browser.module') diff --git a/apk_browser.module b/apk_browser.module index dc769d3..7a7b87c 100644 --- a/apk_browser.module +++ b/apk_browser.module @@ -52,6 +52,13 @@ function apk_browser_menu() { 'page callback' => 'apk_browser_importer', 'access arguments' => array('access apk browser'), ); + $items['admin/config/apk_browser/delete/all'] = array( + 'title' => 'Delete all packages', + 'description' => 'Delete all APK packages', + 'page callback' => 'drupal_get_form', + 'page arguments' => array('apk_browser_delete_all_apk_form'), + 'access arguments' => array('access apk browser'), + ); return $items; } @@ -69,11 +76,35 @@ function apk_browser_settings($form) { '#type' => 'fieldset', '#title' => t('APK browser settings'), ); - $form['settings']['apk_import_debug'] = array( - '#type' => 'checkbox', - '#title' => t('Import debugging'), - '#description' => t('Write import debugging to watchdog'), - '#default_value' => variable_get('apk_import_debug', '0') + $form['settings']['apk_import_delete_all_apk_limit'] = array( + '#type' => 'textfield', + '#size' => '4', + '#title' => t('Node delete batch limit'), + '#description' => t('While deleting all packages, we need to limit the batch process. If it times out please lower this value.'), + '#default_value' => variable_get('apk_import_delete_all_apk_limit', '20') + ); + $form['settings']['apk_import_commit_url'] = array( + '#type' => 'textfield', + '#title' => t('Commit URL'), + '#description' => t('URL to construct a link to repository browser. Use %commit% to be replaced with the actual commit'), + '#default_value' => variable_get('apk_import_commit_url', '') + ); + $feeds = array('0' => t('Disabled')); + if (module_exists('aggregator')) { + $feeds += db_query("SELECT fid,title FROM {aggregator_feed}")->fetchAllKeyed(); + $disabled = FALSE; + $description = t('When enabled, commit title will be searched in this aggregator feed.'); + } else { + $disabled = TRUE; + $description = t('You need to have aggregator enabled and configured to enable this.'); + } + $form['settings']['apk_import_aggregator'] = array( + '#type' => 'select', + '#title' => t('RSS commit lookup'), + '#description' => $description, + '#default_value' => variable_get('apk_import_aggregator','0'), + '#options' => $feeds, + '#disabled' => $disabled, ); return system_settings_form($form); } @@ -293,7 +324,7 @@ function apk_browser_add_apk($package, $arch_tid, $repo_tid) { $node->apk_size['und'][0]['value'] = $value; break; case 'I': - $node->apk_isize['und'][0]['value'] = $value; + $node->apk_installed_size['und'][0]['value'] = $value; break; case 'T': $node->apk_description['und'][0]['value'] = $value; @@ -304,6 +335,18 @@ function apk_browser_add_apk($package, $arch_tid, $repo_tid) { case 'L': $node->apk_license['und'][0]['value'] = $value; break; + case 'o': + $node->apk_origin['und'][0]['value'] = $value; + break; + case 'm': + $node->apk_maintainer['und'][0]['value'] = $value; + break; + case 't': + $node->apk_build_time['und'][0]['value'] = $value; + break; + case 'c': + $node->apk_commit['und'][0]['value'] = $value; + break; //setting this will update package with this nid number case 'update': $node->revision = '1'; @@ -316,6 +359,13 @@ function apk_browser_add_apk($package, $arch_tid, $repo_tid) { $node->apk_depends['und'][]['value'] = $depend; } break; + case 'i': + //do not keep old install if. + unset($node->apk_install_if['und']); + foreach ($value as $installif) { + $node->apk_install_if['und'][]['value'] = $installif; + } + break; } } $node->taxonomy_apk_repo['und'][0]['tid'] = $repo_tid; @@ -427,3 +477,97 @@ function apk_browser_cleanup() { //record timestamp so we can run this function based on age variable_set('apk_browser_cleanup', time()); } + +//create an url from the commit, and if we find it in aggregator we add a title +function apk_browser_commit_url($commit) { + $fid = variable_get('apk_import_aggregator','0'); + if (module_exists('aggregator') && $fid) { + if (!empty($commit)) { + $commit = '%' . $commit . '%'; + } + $title = db_query("SELECT title FROM {aggregator_item} WHERE link LIKE :commit AND fid = :fid", array(':commit' => $commit, ':fid' => $fid))->fetchField(); + $href = str_replace('%commit%', $commit, variable_get('apk_import_commit_url', '')); + $attributes = ($title) ? array('title' => $title, 'class' => 'with-tooltip') : array(); + return l($commit, $href, array('attributes' => $attributes)); + } else { + return FALSE; + } +} + +function apk_browser_preprocess_node($vars) { + if ($vars['node']->type == 'apk') { + if (isset($vars['apk_commit']['0']['value'])) { + $vars['commit_url'] = apk_browser_commit_url($vars['apk_commit']['0']['value']); + } + $path = drupal_get_path('module', 'apk_browser'); + drupal_add_js($path . '/tooltip/tooltip.js'); + drupal_add_js('jQuery().ready(function(){jQuery(".with-tooltip").simpletooltip();});', 'inline'); + } +} + +function apk_browser_delete_all_apk_form($form, $form_state) { + $form = array(); + $question = t('Are you sure you want to remove all packages?'); + $path = 'admin/config/apk_browser'; + $description = t('This action cannot be undone.'); + $yes = t('Remove all'); + $no = t('Cancel'); + return confirm_form($form, $question, $path, $description, $yes, $no); +} + +function apk_browser_delete_all_apk_form_submit($form, &$form_state) { + apk_browser_batch_delete_all_apk(); +} + +function apk_browser_batch_delete_all_apk() { + //define batch options + $batch = array( + 'operations' => array( + array('apk_browser_delete_all_apk', array()), + ), + 'finished' => 'apk_browser_batch_delete_all_apk_finished', + 'title' => t('Deleting all apks'), + 'init_message' => t('Starting deletion of all apks.'), + 'progress_message' => t('Processed @current out of @total.'), + 'error_message' => t('Batch apk delete has encountered an error.'), + ); + //set the batch + batch_set($batch); + //Only used when not run from forms api. forwards to admin page after complete. + batch_process('admin'); +} + +function apk_browser_delete_all_apk(&$context) { + //node delete limit depending on php timeout + $limit = variable_get('apk_import_delete_all_apk_limit', '20'); + if (!isset($context['sandbox']['progress'])) { + $context['sandbox']['progress'] = 0; + $qty = db_query("SELECT nid FROM {node} WHERE type = 'apk'")->rowCount(); + $context['sandbox']['max'] = ceil($qty / $limit); + $context['results']['qty'] = $qty; + } + //delete X nodes set by limit. + $nids = db_query("SELECT nid FROM {node} WHERE type = 'apk' LIMIT :limit", array(':limit' => $limit))->fetchCol(); + node_delete_multiple($nids); + //setting progress to calculate progress and display progress bar. + $context['sandbox']['progress']++; + $context['message'] = t('Deleting @qty packages', array('@qty' => $context['results']['qty'])); + //on last run we do not set finished and will end batch + if ($context['sandbox']['progress'] != $context['sandbox']['max']) { + $context['finished'] = $context['sandbox']['progress'] / $context['sandbox']['max']; + } +} + +function apk_browser_batch_delete_all_apk_finished($success, $results, $operations) { + if ($success) { + // Here we do something meaningful with the results. + $message = $results['qty'] . ' packages deleted.'; + $message .= theme('item_list', $results); + } else { + // An error occurred. + // $operations contains the operations that remained unprocessed. + $error_operation = reset($operations); + $message = t('An error occurred while processing %error_operation with arguments: @arguments', array('%error_operation' => $error_operation[0], '@arguments' => print_r($error_operation[1], TRUE))); + } + drupal_set_message($message); +} -- cgit v1.2.3