]> git.mxchange.org Git - friendica.git/commitdiff
expire and gprobe now moved as well
authorMichael <heluecht@pirati.ca>
Sun, 19 Nov 2017 16:25:13 +0000 (16:25 +0000)
committerMichael <heluecht@pirati.ca>
Sun, 19 Nov 2017 16:25:13 +0000 (16:25 +0000)
include/expire.php [deleted file]
include/gprobe.php [deleted file]
include/identity.php
src/Model/GlobalContact.php
src/Worker/Cron.php
src/Worker/Expire.php [new file with mode: 0644]
src/Worker/GProbe.php [new file with mode: 0644]

diff --git a/include/expire.php b/include/expire.php
deleted file mode 100644 (file)
index 7a3549a..0000000
+++ /dev/null
@@ -1,76 +0,0 @@
-<?php
-
-use Friendica\Core\Config;
-use Friendica\Core\Worker;
-use Friendica\Database\DBM;
-
-function expire_run(&$argv, &$argc){
-       global $a;
-
-       require_once('include/datetime.php');
-       require_once('include/items.php');
-       require_once('include/Contact.php');
-
-       load_hooks();
-
-       if (($argc == 2) && ($argv[1] == 'delete')) {
-               logger('Delete expired items', LOGGER_DEBUG);
-               // physically remove anything that has been deleted for more than two months
-               $r = dba::p("SELECT `id` FROM `item` WHERE `deleted` AND `changed` < UTC_TIMESTAMP() - INTERVAL 60 DAY");
-               while ($row = dba::fetch($r)) {
-                       dba::delete('item', array('id' => $row['id']));
-               }
-               dba::close($r);
-
-               logger('Delete expired items - done', LOGGER_DEBUG);
-
-               // make this optional as it could have a performance impact on large sites
-               if (intval(Config::get('system', 'optimize_items'))) {
-                       q("OPTIMIZE TABLE `item`");
-               }
-               return;
-       } elseif (($argc == 2) && (intval($argv[1]) > 0)) {
-               $user = dba::select('user', array('uid', 'username', 'expire'), array('uid' => $argv[1]), array('limit' => 1));
-               if (DBM::is_result($user)) {
-                       logger('Expire items for user '.$user['uid'].' ('.$user['username'].') - interval: '.$user['expire'], LOGGER_DEBUG);
-                       item_expire($user['uid'], $user['expire']);
-                       logger('Expire items for user '.$user['uid'].' ('.$user['username'].') - done ', LOGGER_DEBUG);
-               }
-               return;
-       } elseif (($argc == 3) && ($argv[1] == 'hook') && is_array($a->hooks) && array_key_exists("expire", $a->hooks)) {
-               foreach ($a->hooks["expire"] as $hook) {
-                       if ($hook[1] == $argv[2]) {
-                               logger("Calling expire hook '" . $hook[1] . "'", LOGGER_DEBUG);
-                               call_single_hook($a, $name, $hook, $data);
-                       }
-               }
-               return;
-       }
-
-       logger('expire: start');
-
-       Worker::add(array('priority' => $a->queue['priority'], 'created' => $a->queue['created'], 'dont_fork' => true),
-                       'expire', 'delete');
-
-       $r = dba::p("SELECT `uid`, `username` FROM `user` WHERE `expire` != 0");
-       while ($row = dba::fetch($r)) {
-               logger('Calling expiry for user '.$row['uid'].' ('.$row['username'].')', LOGGER_DEBUG);
-               Worker::add(array('priority' => $a->queue['priority'], 'created' => $a->queue['created'], 'dont_fork' => true),
-                               'expire', (int)$row['uid']);
-       }
-       dba::close($r);
-
-       logger('expire: calling hooks');
-
-       if (is_array($a->hooks) && array_key_exists('expire', $a->hooks)) {
-               foreach ($a->hooks['expire'] as $hook) {
-                       logger("Calling expire hook for '" . $hook[1] . "'", LOGGER_DEBUG);
-                       Worker::add(array('priority' => $a->queue['priority'], 'created' => $a->queue['created'], 'dont_fork' => true),
-                                       'expire', 'hook', $hook[1]);
-               }
-       }
-
-       logger('expire: end');
-
-       return;
-}
diff --git a/include/gprobe.php b/include/gprobe.php
deleted file mode 100644 (file)
index a6b46af..0000000
+++ /dev/null
@@ -1,64 +0,0 @@
-<?php
-/**
- * @file include/gprobe.php
- */
-use Friendica\Core\Cache;
-use Friendica\Core\Config;
-use Friendica\Database\DBM;
-use Friendica\Model\GlobalContact;
-use Friendica\Network\Probe;
-use Friendica\Protocol\PortableContact;
-
-require_once 'include/datetime.php';
-
-function gprobe_run(&$argv, &$argc)
-{
-       if ($argc != 2) {
-               return;
-       }
-       $url = $argv[1];
-
-       $r = q(
-               "SELECT `id`, `url`, `network` FROM `gcontact` WHERE `nurl` = '%s' ORDER BY `id` LIMIT 1",
-               dbesc(normalise_link($url))
-       );
-
-       logger("gprobe start for ".normalise_link($url), LOGGER_DEBUG);
-
-       if (!DBM::is_result($r)) {
-               // Is it a DDoS attempt?
-               $urlparts = parse_url($url);
-
-               $result = Cache::get("gprobe:".$urlparts["host"]);
-               if (!is_null($result)) {
-                       if (in_array($result["network"], array(NETWORK_FEED, NETWORK_PHANTOM))) {
-                               logger("DDoS attempt detected for ".$urlparts["host"]." by ".$_SERVER["REMOTE_ADDR"].". server data: ".print_r($_SERVER, true), LOGGER_DEBUG);
-                               return;
-                       }
-               }
-
-               $arr = Probe::uri($url);
-
-               if (is_null($result)) {
-                       Cache::set("gprobe:".$urlparts["host"], $arr);
-               }
-
-               if (!in_array($arr["network"], array(NETWORK_FEED, NETWORK_PHANTOM))) {
-                       GlobalContact::update($arr);
-               }
-
-               $r = q(
-                       "SELECT `id`, `url`, `network` FROM `gcontact` WHERE `nurl` = '%s' ORDER BY `id` LIMIT 1",
-                       dbesc(normalise_link($url))
-               );
-       }
-       if (DBM::is_result($r)) {
-               // Check for accessibility and do a poco discovery
-               if (PortableContact::lastUpdated($r[0]['url'], true) && ($r[0]["network"] == NETWORK_DFRN)) {
-                       PortableContact::loadWorker(0, 0, $r[0]['id'], str_replace('/profile/', '/poco/', $r[0]['url']));
-               }
-       }
-
-       logger("gprobe end for ".normalise_link($url), LOGGER_DEBUG);
-       return;
-}
index 727073ea679e0dce4106dad5d1cee631d2cd502a..6991a8dcc9e64b0912e8dab0030a2d76853bfbdc 100644 (file)
@@ -939,7 +939,7 @@ function zrl_init(App $a)
                        return;
                }
 
-               Worker::add(PRIORITY_LOW, 'gprobe', $tmp_str);
+               Worker::add(PRIORITY_LOW, 'GProbe', $tmp_str);
                $arr = array('zrl' => $tmp_str, 'url' => $a->cmd);
                call_hooks('zrl_init', $arr);
        }
index 2e16c687f970cab0de0b46844b3372036277be0d..1ca814789b4d59058ca8b0fe9c0e9374ef202544 100644 (file)
@@ -688,7 +688,7 @@ class GlobalContact
 
                if ($doprobing) {
                        logger("Last Contact: ". $last_contact_str." - Last Failure: ".$last_failure_str." - Checking: ".$contact["url"], LOGGER_DEBUG);
-                       Worker::add(PRIORITY_LOW, 'gprobe', $contact["url"]);
+                       Worker::add(PRIORITY_LOW, 'GProbe', $contact["url"]);
                }
 
                return $gcontact_id;
index b3f0f1f6913bc25e8a91dfcdc40762d88ed1e899..429aed3d9633aa07aaadb2bd05cf15d5da10410c 100644 (file)
@@ -79,7 +79,7 @@ Class Cron {
 
                        Config::set('system', 'last_expire_day', $d2);
 
-                       Worker::add(PRIORITY_LOW, 'expire');
+                       Worker::add(PRIORITY_LOW, 'Expire');
 
                        Worker::add(PRIORITY_MEDIUM, 'DBClean');
 
diff --git a/src/Worker/Expire.php b/src/Worker/Expire.php
new file mode 100644 (file)
index 0000000..ac2577e
--- /dev/null
@@ -0,0 +1,85 @@
+<?php
+/**
+ * @file src/Worker/Expire.php
+ * @brief Expires old item entries
+ */
+
+namespace Friendica\Worker;
+
+use Friendica\Core\Config;
+use Friendica\Core\Worker;
+use Friendica\Database\DBM;
+use dba;
+
+class Expire {
+       public static function execute($param = '', $hook_name = '') {
+               global $a;
+
+               require_once('include/datetime.php');
+               require_once('include/items.php');
+               require_once('include/Contact.php');
+
+               load_hooks();
+
+               if ($param == 'delete') {
+                       logger('Delete expired items', LOGGER_DEBUG);
+                       // physically remove anything that has been deleted for more than two months
+                       $r = dba::p("SELECT `id` FROM `item` WHERE `deleted` AND `changed` < UTC_TIMESTAMP() - INTERVAL 60 DAY");
+                       while ($row = dba::fetch($r)) {
+                               dba::delete('item', array('id' => $row['id']));
+                       }
+                       dba::close($r);
+
+                       logger('Delete expired items - done', LOGGER_DEBUG);
+
+                       // make this optional as it could have a performance impact on large sites
+                       if (intval(Config::get('system', 'optimize_items'))) {
+                               dba::e("OPTIMIZE TABLE `item`");
+                       }
+                       return;
+               } elseif (intval($param) > 0) {
+                       $user = dba::select('user', array('uid', 'username', 'expire'), array('uid' => $param), array('limit' => 1));
+                       if (DBM::is_result($user)) {
+                               logger('Expire items for user '.$user['uid'].' ('.$user['username'].') - interval: '.$user['expire'], LOGGER_DEBUG);
+                               item_expire($user['uid'], $user['expire']);
+                               logger('Expire items for user '.$user['uid'].' ('.$user['username'].') - done ', LOGGER_DEBUG);
+                       }
+                       return;
+               } elseif (!empty($hook_name) && ($param == 'hook') && is_array($a->hooks) && array_key_exists("expire", $a->hooks)) {
+                       foreach ($a->hooks["expire"] as $hook) {
+                               if ($hook[1] == $hook_name) {
+                                       logger("Calling expire hook '" . $hook[1] . "'", LOGGER_DEBUG);
+                                       call_single_hook($a, $name, $hook, $data);
+                               }
+                       }
+                       return;
+               }
+
+               logger('expire: start');
+
+               Worker::add(array('priority' => $a->queue['priority'], 'created' => $a->queue['created'], 'dont_fork' => true),
+                               'expire', 'delete');
+
+               $r = dba::p("SELECT `uid`, `username` FROM `user` WHERE `expire` != 0");
+               while ($row = dba::fetch($r)) {
+                       logger('Calling expiry for user '.$row['uid'].' ('.$row['username'].')', LOGGER_DEBUG);
+                       Worker::add(array('priority' => $a->queue['priority'], 'created' => $a->queue['created'], 'dont_fork' => true),
+                                       'expire', (int)$row['uid']);
+               }
+               dba::close($r);
+
+               logger('expire: calling hooks');
+
+               if (is_array($a->hooks) && array_key_exists('expire', $a->hooks)) {
+                       foreach ($a->hooks['expire'] as $hook) {
+                               logger("Calling expire hook for '" . $hook[1] . "'", LOGGER_DEBUG);
+                               Worker::add(array('priority' => $a->queue['priority'], 'created' => $a->queue['created'], 'dont_fork' => true),
+                                               'expire', 'hook', $hook[1]);
+                       }
+               }
+
+               logger('expire: end');
+
+               return;
+       }
+}
diff --git a/src/Worker/GProbe.php b/src/Worker/GProbe.php
new file mode 100644 (file)
index 0000000..bfe277f
--- /dev/null
@@ -0,0 +1,65 @@
+<?php
+/**
+ * @file include/gprobe.php
+ */
+use Friendica\Core\Cache;
+use Friendica\Core\Config;
+use Friendica\Database\DBM;
+use Friendica\Model\GlobalContact;
+use Friendica\Network\Probe;
+use Friendica\Protocol\PortableContact;
+
+require_once 'include/datetime.php';
+
+class GProbe {
+       function execute($url = '')
+       {
+               if (empty($url)) {
+                       return;
+               }
+
+               $r = q(
+                       "SELECT `id`, `url`, `network` FROM `gcontact` WHERE `nurl` = '%s' ORDER BY `id` LIMIT 1",
+                       dbesc(normalise_link($url))
+               );
+
+               logger("gprobe start for ".normalise_link($url), LOGGER_DEBUG);
+
+               if (!DBM::is_result($r)) {
+                       // Is it a DDoS attempt?
+                       $urlparts = parse_url($url);
+
+                       $result = Cache::get("gprobe:".$urlparts["host"]);
+                       if (!is_null($result)) {
+                               if (in_array($result["network"], array(NETWORK_FEED, NETWORK_PHANTOM))) {
+                                       logger("DDoS attempt detected for ".$urlparts["host"]." by ".$_SERVER["REMOTE_ADDR"].". server data: ".print_r($_SERVER, true), LOGGER_DEBUG);
+                                       return;
+                               }
+                       }
+
+                       $arr = Probe::uri($url);
+
+                       if (is_null($result)) {
+                               Cache::set("gprobe:".$urlparts["host"], $arr);
+                       }
+
+                       if (!in_array($arr["network"], array(NETWORK_FEED, NETWORK_PHANTOM))) {
+                               GlobalContact::update($arr);
+                       }
+
+                       $r = q(
+                               "SELECT `id`, `url`, `network` FROM `gcontact` WHERE `nurl` = '%s' ORDER BY `id` LIMIT 1",
+                               dbesc(normalise_link($url))
+                       );
+               }
+               if (DBM::is_result($r)) {
+                       // Check for accessibility and do a poco discovery
+                       if (PortableContact::lastUpdated($r[0]['url'], true) && ($r[0]["network"] == NETWORK_DFRN)) {
+                               PortableContact::loadWorker(0, 0, $r[0]['id'], str_replace('/profile/', '/poco/', $r[0]['url']));
+                       }
+               }
+
+               logger("gprobe end for ".normalise_link($url), LOGGER_DEBUG);
+               return;
+       }
+}