summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCarlo Landmeter <clandmeter@gmail.com>2011-04-28 12:15:31 +0200
committerCarlo Landmeter <clandmeter@gmail.com>2011-04-28 12:15:31 +0200
commit03f275faaffa748a9de996972f9886bc426aafc0 (patch)
tree21722b803108dcc76a3df3518f19101643a8b383
parent92b876c4fde0673484ba3c2b3c04257e07da51a9 (diff)
downloadapk_browser-03f275faaffa748a9de996972f9886bc426aafc0.tar.bz2
apk_browser-03f275faaffa748a9de996972f9886bc426aafc0.tar.xz
add enable/disable switch for cron import and add repo check to import/cleanup
-rw-r--r--apk_browser.module125
1 files changed, 69 insertions, 56 deletions
diff --git a/apk_browser.module b/apk_browser.module
index d428ce9..a28320e 100644
--- a/apk_browser.module
+++ b/apk_browser.module
@@ -89,6 +89,12 @@ function apk_browser_settings($form) {
'#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', '')
);
+ $form['settings']['apk_import_status'] = array(
+ '#type' => 'checkbox',
+ '#title' => t('Enable apk import'),
+ '#description' => t('Enable or disable package importing and cleanup'),
+ '#default_value' => variable_get('apk_import_status', '0')
+ );
$feeds = array('0' => t('Disabled'));
if (module_exists('aggregator')) {
$feeds += db_query("SELECT fid,title FROM {aggregator_feed}")->fetchAllKeyed();
@@ -110,10 +116,12 @@ function apk_browser_settings($form) {
}
function apk_browser_cron() {
- apk_browser_importer();
- //cleanup old packages ones in 24h
- if ((time() - variable_get('apk_browser_cleanup', '0')) > '86400') {
- apk_browser_cleanup();
+ if (variable_get('apk_import_status', '0')) {
+ apk_browser_importer();
+ //cleanup old packages ones in 24h
+ if ((time() - variable_get('apk_browser_cleanup', '0')) > '86400') {
+ apk_browser_cleanup();
+ }
}
}
@@ -251,16 +259,17 @@ function apk_browser_repositories_list() {
function apk_browser_importer() {
$repos = variable_get('apk_repositories', NULL);
- foreach ($repos as $id => $repo) {
- $apk_string = file_get_contents($repo['url']);
- $checksum = md5($apk_string);
- $checksum_db = variable_get('apk_import_checksum_' . $id, '');
- if ($checksum != $checksum_db) {
- $repo_apks = apk_browser_apkindex_reader($apk_string);
- $skipped = '0';
- $updated = array();
- $added = array();
- $db_apks = db_query("
+ if ($repos) {
+ foreach ($repos as $id => $repo) {
+ $apk_string = file_get_contents($repo['url']);
+ $checksum = md5($apk_string);
+ $checksum_db = variable_get('apk_import_checksum_' . $id, '');
+ if ($checksum != $checksum_db) {
+ $repo_apks = apk_browser_apkindex_reader($apk_string);
+ $skipped = '0';
+ $updated = array();
+ $added = array();
+ $db_apks = db_query("
SELECT node.nid, node.title,
csum.apk_checksum_value as csum
FROM {node},
@@ -273,28 +282,28 @@ function apk_browser_importer() {
AND node.nid = csum.entity_id
AND arch.taxonomy_apk_arch_tid = :arch
AND repo.taxonomy_apk_repo_tid = :repo", array(
- ':arch' => $repo['arch'],
- ':repo' => $repo['repo']
- )
- )->fetchAllAssoc('title');
- foreach ($repo_apks as $title => $repo_apk) {
- if (isset($db_apks[$title])) {
- if ($repo_apk['C'] != $db_apks[$title]->csum) {
- $repo_apk['update'] = $db_apks[$title]->nid;
- $updated[] = apk_browser_add_apk($repo_apk, $repo['arch'], $repo['repo']);
+ ':arch' => $repo['arch'],
+ ':repo' => $repo['repo']
+ )
+ )->fetchAllAssoc('title');
+ foreach ($repo_apks as $title => $repo_apk) {
+ if (isset($db_apks[$title])) {
+ if ($repo_apk['C'] != $db_apks[$title]->csum) {
+ $repo_apk['update'] = $db_apks[$title]->nid;
+ $updated[] = apk_browser_add_apk($repo_apk, $repo['arch'], $repo['repo']);
+ } else {
+ $skipped++;
+ }
} else {
- $skipped++;
+ $added[] = apk_browser_add_apk($repo_apk, $repo['arch'], $repo['repo']);
}
- } else {
- $added[] = apk_browser_add_apk($repo_apk, $repo['arch'], $repo['repo']);
}
+ watchdog('apk', 'Added @added and updated @updated and skipped @skipped packages for repo @repo', array('@added' => count($added), '@updated' => count($updated), '@skipped' => $skipped, '@repo' => $id), WATCHDOG_INFO, NULL);
+ variable_set('apk_import_checksum_' . $id, $checksum);
}
- watchdog('apk', 'Added @added and updated @updated and skipped @skipped packages for repo @repo', array('@added' => count($added), '@updated' => count($updated), '@skipped' => $skipped, '@repo' => $id), WATCHDOG_INFO, NULL);
- variable_set('apk_import_checksum_' . $id, $checksum);
- } else {
- //do not spam watchdog
- //watchdog('apk', 'APK index @repo is up-to-date', array('@repo' => $id), WATCHDOG_INFO, NULL);
}
+ } else {
+ watchdog('apk', 'No repositories found. Please add them first', array(), WATCHDOG_WARNING, NULL);
}
}
@@ -440,16 +449,17 @@ function apk_browser_views_api() {
function apk_browser_cleanup() {
//load repo's and clean them
$repos = variable_get('apk_repositories', NULL);
- watchdog('apk', 'Starting apk cleanup', array(), WATCHDOG_INFO, NULL);
- foreach ($repos as $id => $repo) {
- //create array from apkindex and filter out name
- $apk_string = file_get_contents($repo['url']);
- $packages = apk_browser_apkindex_reader($apk_string);
- foreach ($packages as $package) {
- $apk_names[] = $package['P'];
- }
- //fetch all packages from db matching arch repo
- $db_apk = db_query("
+ if ($repos) {
+ watchdog('apk', 'Starting apk cleanup', array(), WATCHDOG_INFO, NULL);
+ foreach ($repos as $id => $repo) {
+ //create array from apkindex and filter out name
+ $apk_string = file_get_contents($repo['url']);
+ $packages = apk_browser_apkindex_reader($apk_string);
+ foreach ($packages as $package) {
+ $apk_names[] = $package['P'];
+ }
+ //fetch all packages from db matching arch repo
+ $db_apk = db_query("
SELECT node.nid, node.title
FROM {node},
{field_data_taxonomy_apk_arch} AS arch,
@@ -459,23 +469,26 @@ function apk_browser_cleanup() {
AND node.status = '1'
AND arch.taxonomy_apk_arch_tid = :arch
AND repo.taxonomy_apk_repo_tid = :repo", array(
- ':arch' => $repo['arch'],
- ':repo' => $repo['repo']
- )
- )->fetchAllKeyed(0, 1);
- //check which packages are in db but not in repo
- $diff = array_diff($db_apk, $apk_names);
- foreach ($diff as $nid => $disable) {
- //load the node and unpublish it
- $node = node_load($nid);
- $node->status = '0';
- $node = node_submit($node);
- node_save($node);
- watchdog('apk', 'Package @apk has been disabled', array('@apk' => $disable), WATCHDOG_INFO, NULL);
+ ':arch' => $repo['arch'],
+ ':repo' => $repo['repo']
+ )
+ )->fetchAllKeyed(0, 1);
+ //check which packages are in db but not in repo
+ $diff = array_diff($db_apk, $apk_names);
+ foreach ($diff as $nid => $disable) {
+ //load the node and unpublish it
+ $node = node_load($nid);
+ $node->status = '0';
+ $node = node_submit($node);
+ node_save($node);
+ watchdog('apk', 'Package @apk has been disabled', array('@apk' => $disable), WATCHDOG_INFO, NULL);
+ }
}
+ //record timestamp so we can run this function based on age
+ variable_set('apk_browser_cleanup', time());
+ } else {
+ watchdog('apk', 'No repositories found. Please add them first', array(), WATCHDOG_WARNING, NULL);
}
- //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