summaryrefslogtreecommitdiffstats
path: root/apk_browser.module
diff options
context:
space:
mode:
authorCarlo Landmeter <clandmeter@gmail.com>2011-04-15 13:00:48 +0200
committerCarlo Landmeter <clandmeter@gmail.com>2011-04-15 13:00:48 +0200
commit95803dc0bcc703c4ebf74b62233f671353555faf (patch)
tree74b31e66476b0645fb0f42718132eabc6e330c24 /apk_browser.module
parentc1cd83639d842f948c54665300f2b5b9624f85a3 (diff)
downloadapk_browser-95803dc0bcc703c4ebf74b62233f671353555faf.tar.bz2
apk_browser-95803dc0bcc703c4ebf74b62233f671353555faf.tar.xz
added cleanup function for removed pkgs and set proper languages for nodes
Diffstat (limited to 'apk_browser.module')
-rw-r--r--apk_browser.module81
1 files changed, 63 insertions, 18 deletions
diff --git a/apk_browser.module b/apk_browser.module
index e712681..903f5b1 100644
--- a/apk_browser.module
+++ b/apk_browser.module
@@ -79,7 +79,11 @@ function apk_browser_settings($form) {
}
function apk_browser_cron() {
- apk_browser_import_apk();
+ apk_browser_import_apk();
+ //cleanup old packages ones in 24h
+ if ((time() - variable_get('apk_browser_cleanup', '0')) > '86400') {
+ apk_browser_cleanup();
+ }
}
function apk_browser_repository_delete_form($form, &$form_state, $rid) {
@@ -224,7 +228,7 @@ function apk_browser_import_apk() {
$apk_string = file_get_contents($repo['url']);
//no need to update if apkindex is not changed
$checksum = md5($apk_string);
- $checksum_db = variable_get('apk_import_checksum_'.$id, '');
+ $checksum_db = variable_get('apk_import_checksum_' . $id, '');
if (($debug == '1') || ($checksum != $checksum_db)) {
if ($debug == '1') {
watchdog('apk', 'APK importer running in debug mode!', array(), WATCHDOG_WARNING, NULL);
@@ -261,7 +265,7 @@ function apk_browser_import_apk() {
}
}
watchdog('apk', 'Added @added and updated @updated and skipped @skipped packages', array('@added' => count($added), '@updated' => count($updated), '@skipped' => $skipped), WATCHDOG_INFO, NULL);
- variable_set('apk_import_checksum_'.$id, $checksum);
+ variable_set('apk_import_checksum_' . $id, $checksum);
} else {
watchdog('apk', 'APK index is up-to-date', array(), WATCHDOG_INFO, NULL);
}
@@ -311,22 +315,23 @@ function apk_browser_add_apk($package, $arch_tid, $repo_tid) {
$node->nid = $value;
break;
case 'D':
- //do not keep old depends.
+ //do not keep old depends.
unset($node->apk_depends['und']);
- foreach ($value as $depend) {
- $node->apk_depends['und'][]['value'] = $depend;
+ foreach ($value as $depend) {
+ $node->apk_depends['und'][]['value'] = $depend;
}
break;
}
}
$node->taxonomy_apk_repo['und'][0]['tid'] = $repo_tid;
$node->taxonomy_apk_arch['und'][0]['tid'] = $arch_tid;
+ $node->language = 'und';
$node = node_submit($node);
node_save($node);
//create a human path based on repo and arch
$alias = array(
- 'source' => 'node'.'/'.$node->nid,
- 'alias' => 'apk/'.$repo->name.'/'.$arch->name.'/'.$node->title
+ 'source' => 'node' . '/' . $node->nid,
+ 'alias' => 'apk/' . $repo->name . '/' . $arch->name . '/' . $node->title
);
path_save($alias);
return $node->nid;
@@ -348,14 +353,14 @@ function apk_browser_apkindex_reader($apk_string) {
//convert packages lines into array
$apackage = preg_split("`\n`", $package);
foreach ($apackage as $apk_line) {
- switch ($apk_line[0]) {
- //depend and install_if lines
- case "D":
- case "i":
- $apackages[$key][$apk_line[0]] = explode(" ", substr($apk_line, 2));
- break;
- //other apk variables
- default:
+ switch ($apk_line[0]) {
+ //depend and install_if lines
+ case "D":
+ case "i":
+ $apackages[$key][$apk_line[0]] = explode(" ", substr($apk_line, 2));
+ break;
+ //other apk variables
+ default:
$apackages[$key][$apk_line[0]] = substr($apk_line, 2);
}
}
@@ -389,8 +394,48 @@ function apk_browser_apk_check($title, $arch, $repo) {
)->fetchAssoc();
}
-
//this is needed for auto views integration
function apk_browser_views_api() {
- return array('api' => 3.0);
+ return array('api' => 3.0);
+}
+
+//disable packages which seem to have gone
+function apk_browser_cleanup() {
+ //load repo's and clean them
+ $repos = variable_get('apk_repositories', 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,
+ {field_data_taxonomy_apk_repo} AS repo
+ WHERE node.nid = arch.entity_id
+ AND node.nid = repo.entity_id
+ 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);
+ }
+ }
+ //record timestamp so we can run this function based on age
+ variable_set('apk_browser_cleanup', time());
}