summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--apk_browser.module35
1 files changed, 35 insertions, 0 deletions
diff --git a/apk_browser.module b/apk_browser.module
index 39b4e49..e15a323 100644
--- a/apk_browser.module
+++ b/apk_browser.module
@@ -115,6 +115,10 @@ function apk_browser_cron() {
if ((time() - variable_get('apk_browser_cleanup', '0')) > '86400') {
apk_browser_cleanup();
}
+ //set maintainer if users signs up after the package has been imported
+ if ((time() - variable_get('apk_browser_assign_maintainer', '0')) > '86400') {
+ apk_browser_assign_maintainer();
+ }
}
}
@@ -344,6 +348,9 @@ function apk_browser_add_apk($package, $arch_tid, $repo_tid) {
break;
case 'm':
$node->apk_maintainer['und'][0]['value'] = $value;
+ //lookup the maintainer from drupal db. if not found we use 0 as anonymous.
+ $uid = apk_browser_maintainer_to_user($value);
+ $node->uid = ($uid) ? $uid : '0';
break;
case 't':
$node->apk_build_time['und'][0]['value'] = $value;
@@ -695,3 +702,31 @@ function apk_browser_block_view($delta = '') {
}
return ($block['content']) ? $block : FALSE;
}
+
+// If possible convert the maintainer field to a valid email address
+// and return the drupal uid
+function apk_browser_maintainer_to_user($maintainer) {
+ $email = mailparse_rfc822_parse_addresses($maintainer);
+ if (filter_var($email[0]['address'], FILTER_VALIDATE_EMAIL)) {
+ return db_query("SELECT uid FROM {users} WHERE mail = :mail AND status = '1'", array(':mail' => $email[0]['address'])
+ )->fetchField();
+ }
+ return FALSE;
+}
+
+function apk_browser_assign_maintainer() {
+ $updated = array();
+ $rows = db_query("SELECT entity_id, apk_maintainer_value FROM {field_data_apk_maintainer}")->fetchAllKeyed(0, 1);
+ foreach ($rows as $nid => $maintainer) {
+ $uid = apk_browser_maintainer_to_user($maintainer);
+ if ($uid) {
+ $updated[] = db_update('node')
+ ->fields(array('uid' => $uid))
+ ->condition('nid', $nid)
+ ->condition('uid', $uid, '!=')
+ ->execute();
+ }
+ }
+ variable_set('apk_browser_assign_maintainer', time());
+ watchdog('apk', 'Updated @qty package maintainers', array('@qty' => count(array_filter($updated))), WATCHDOG_INFO, NULL);
+}