Commit 25ff216c authored by Mario's avatar Mario

Merge branch '4.4RC'

parents 06ff9bbb b3124a3b
Copyright (c) 2019 Hubzilla Community
All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
......@@ -84,7 +84,7 @@ if (file_exists($cachefile) && time() - $cachetime < filemtime($cachefile)) {
header('Pragma: public');
header('Cache-Control: max-age=86400');
header('Expires: '. gmdate('D, d M Y H:i:s \G\M\T', time() + 86400));
header('Content-Type: image/jpg');
header('Content-Type: image/jpeg');
readfile($cachefile);
exit;
}
......
......@@ -4,7 +4,7 @@ namespace Zotlabs\Module;
use App;
use Zotlabs\Lib\Apps;
use Zotlabs\Zot6\HTTPSig;
use Zotlabs\Web\HTTPSig;
use Zotlabs\Web\Controller;
class Content_import extends Controller {
......
<?php
use Zotlabs\Zot6\HTTPSig;
use Zotlabs\Web\HTTPSig;
require_once('include/cli_startup.php');
require_once('include/attach.php');
......
<?php
use Zotlabs\Zot6\HTTPSig;
use Zotlabs\Web\HTTPSig;
require_once('include/cli_startup.php');
require_once('include/attach.php');
......
......@@ -7,6 +7,7 @@ use Zotlabs\Lib\Apps;
use Zotlabs\Web\Controller;
require_once('addon/diaspora/util.php'); // needed for diaspora_build_relay_tags()
require_once('addon/diaspora/diaspora.php'); // needed for diaspora_init_relay()
class Diaspora extends Controller {
......@@ -59,6 +60,8 @@ class Diaspora extends Controller {
return $o;
}
diaspora_init_relay();
$pubcomments = get_pconfig(local_channel(),'system','diaspora_public_comments',1);
$hijacking = get_pconfig(local_channel(),'system','prevent_tag_hijacking');
$signing = get_pconfig(local_channel(),'diaspora','sign_unsigned');
......
......@@ -195,7 +195,7 @@ function gallery_prepare_body(&$arr) {
justifiedGalleryActive = true;
$('#gallery-wrapper-$id').justifiedGallery({
captions: false,
rowHeight: '$row_height',
rowHeight: $row_height,
lastRow: '$last_row',
justifyThreshold: 0.5,
border: 0,
......
......@@ -98,7 +98,7 @@ function gravatar_get_profile_photo($a, &$b) {
}
$i = z_fetch_url($url);
if ($i['success']) {
$b['mimetype'] = 'image/jpg';
$b['mimetype'] = 'image/jpeg';
$b['data'] = $i['body'];
}
}
......
<?php
use Zotlabs\Web\HTTPSig;
require_once('include/cli_startup.php');
require_once('include/attach.php');
require_once('include/import.php');
......@@ -21,8 +23,7 @@ $hz_server = urldecode($argv[3]);
$headers = [];
$headers['X-API-Token'] = random_string();
$headers['X-API-Request'] = $hz_server . '/api/z/1.0/file/export?f=&file_id=' . $attach_id;
$headers = \Zotlabs\Web\HTTPSig::create_sig('',$headers,$channel['channel_prvkey'],
'acct:' . $channel['channel_address'] . '@' . \App::get_hostname(),false,true,'sha512');
$headers = HTTPSig::create_sig($headers,$channel['channel_prvkey'], 'acct:' . channel_reddress($channel),true,'sha512');
$x = z_fetch_url($hz_server . '/api/z/1.0/file/export?f=&file_id=' . $attach_id,false,$redirects,[ 'headers' => $headers ]);
......
......@@ -8,6 +8,7 @@
* Maintainer: Mike Macgirvin <mike@macgirvin.com>
*/
use Zotlabs\Web\HTTPSig;
function hzfiles_install() {}
function hzfiles_uninstall() {}
......@@ -33,8 +34,7 @@ function hzfiles_post(&$a) {
$headers = [];
$headers['X-API-Token'] = random_string();
$headers['X-API-Request'] = $hz_server . '/api/z/1.0/files?f=&since=' . urlencode($since) . '&until=' . urlencode($until);
$headers = \Zotlabs\Web\HTTPSig::create_sig('',$headers,$channel['channel_prvkey'],
'acct:' . $channel['channel_address'] . '@' . \App::get_hostname(),false,true,'sha512');
$headers = HTTPSig::create_sig($headers,$channel['channel_prvkey'], 'acct:' . channel_reddress($channel),true,'sha512');
$x = z_fetch_url($hz_server . '/api/z/1.0/files?f=&since=' . urlencode($since) . '&until=' . urlencode($until),false,$redirects,[ 'headers' => $headers ]);
......
......@@ -53,21 +53,10 @@ function openstreetmap_location($a, &$item) {
* ?mlat=lat&mlon=lon for markers.
*/
$tmsserver = get_config('openstreetmap', 'tmsserver');
if(! $tmsserver)
$tmsserver = 'http://www.openstreetmap.org';
$nomserver = get_config('openstreetmap', 'nomserver');
if(! $nomserver)
$nomserver = 'http://nominatim.openstreetmap.org/search.php';
$zoom = get_config('openstreetmap', 'zoom');
if(! $zoom)
$zoom = 16;
$marker = get_config('openstreetmap', 'marker');
if(! $marker)
$marker = 0;
$tmsserver = get_config('openstreetmap', 'tmsserver', 'https://www.openstreetmap.org');
$nomserver = get_config('openstreetmap', 'nomserver', 'https://nominatim.openstreetmap.org/search.php');
$zoom = get_config('openstreetmap', 'zoom', 16);
$marker = get_config('openstreetmap', 'marker', 1);
$location = '';
$coord = '';
......@@ -98,11 +87,7 @@ function openstreetmap_location($a, &$item) {
function openstreetmap_generate_named_map(&$a,&$b) {
$nomserver = get_config('openstreetmap', 'nomserver');
if(! $nomserver)
$nomserver = 'http://nominatim.openstreetmap.org/search.php';
$nomserver = get_config('openstreetmap', 'nomserver', 'https://nominatim.openstreetmap.org/search.php');
$args = '?q=' . urlencode($b['location']) . '&format=json';
$x = z_fetch_url($nomserver . $args);
......@@ -118,21 +103,9 @@ function openstreetmap_generate_named_map(&$a,&$b) {
}
function openstreetmap_generate_map(&$a,&$b) {
$tmsserver = get_config('openstreetmap', 'tmsserver');
if(! $tmsserver)
$tmsserver = 'http://www.openstreetmap.org';
if(strpos(z_root(),'https:') !== false)
$tmsserver = str_replace('http:','https:',$tmsserver);
$zoom = get_config('openstreetmap', 'zoom');
if(! $zoom)
$zoom = 16;
$marker = get_config('openstreetmap', 'marker');
if(! $marker)
$marker = 0;
$tmsserver = get_config('openstreetmap', 'tmsserver', 'https://www.openstreetmap.org');
$zoom = get_config('openstreetmap', 'zoom', 16);
$marker = get_config('openstreetmap', 'marker', 1);
$lat = $b['lat']; // round($b['lat'], 5);
$lon = $b['lon']; // round($b['lon'], 5);
......@@ -152,18 +125,10 @@ function openstreetmap_generate_map(&$a,&$b) {
function openstreetmap_plugin_admin(&$a, &$o) {
$t = get_markup_template("admin.tpl", "addon/openstreetmap/");
$tmsserver = get_config('openstreetmap', 'tmsserver');
if(! $tmsserver)
$tmsserver = 'http://www.openstreetmap.org';
$nomserver = get_config('openstreetmap', 'nomserver');
if(! $nomserver)
$nomserver = 'http://nominatim.openstreetmap.org/search.php';
$zoom = get_config('openstreetmap', 'zoom');
if(! $zoom)
$zoom = 16;
$marker = get_config('openstreetmap', 'marker');
if(! $marker)
$marker = 0;
$tmsserver = get_config('openstreetmap', 'tmsserver', 'https://www.openstreetmap.org');
$nomserver = get_config('openstreetmap', 'nomserver', 'https://nominatim.openstreetmap.org/search.php');
$zoom = get_config('openstreetmap', 'zoom', 16);
$marker = get_config('openstreetmap', 'marker', 1);
$o = replace_macros($t, array(
'$submit' => t('Submit'),
......@@ -176,8 +141,8 @@ function openstreetmap_plugin_admin(&$a, &$o) {
function openstreetmap_plugin_admin_post(&$a) {
$urltms = ((x($_POST, 'tmsserver')) ? notags(trim($_POST['tmsserver'])) : '');
$urlnom = ((x($_POST, 'nomserver')) ? notags(trim($_POST['nomserver'])) : '');
$zoom = ((x($_POST, 'zoom')) ? intval(trim($_POST['zoom'])) : '16');
$marker = ((x($_POST, 'marker')) ? intval(trim($_POST['marker'])) : '0');
$zoom = ((x($_POST, 'zoom')) ? intval(trim($_POST['zoom'])) : 16);
$marker = ((x($_POST, 'marker')) ? intval(trim($_POST['marker'])) : 1);
set_config('openstreetmap', 'tmsserver', $urltms);
set_config('openstreetmap', 'nomserver', $urlnom);
set_config('openstreetmap', 'zoom', $zoom);
......
......@@ -2,7 +2,7 @@
/**
* Name: Photo Cache
* Description: Local photo cache implementation
* Version: 0.2.7
* Version: 0.2.8
* Author: Max Kostikov
* Maintainer: max@kostikov.co
* MinVersion: 3.9.5
......@@ -94,16 +94,11 @@ function photocache_mode_key($key) {
*
*/
function photocache_isgrid($url) {
if(strpos($url, z_root()) === 0)
return true;
if(photocache_mode_key('grid'))
return false;
$r = q("SELECT * FROM hubloc WHERE hubloc_host = '%s' AND hubloc_network LIKE '%s' LIMIT 1",
dbesc(parse_url($url, PHP_URL_HOST)),
dbesc('zot%')
);
return ($r ? true : false);
return is_matrix_url($url);
}
......@@ -143,7 +138,7 @@ function photocache_hash($str, $alg = 'sha256') {
return logger('invalid channel ID received ' . $s['uid'], LOGGER_DEBUG);
$matches = null;
$cnt = preg_match_all("/\<img(.+?)src=([\"|'])(https?\:.*?)\\2(.*?)\>/", $s['body'], $matches, PREG_SET_ORDER);
$cnt = preg_match_all("/\<img(.+?)src=([\"'])(https?\:.*?)\\2(.*?)\>/", $s['body'], $matches, PREG_SET_ORDER);
if($cnt) {
$ph = photo_factory('');
foreach ($matches as $match) {
......@@ -243,7 +238,7 @@ function photocache_url(&$cache = array()) {
}
$exp = strtotime($r['expires']);
$url = (($exp - 60 < time()) ? htmlspecialchars_decode($r['display_path']) : '');
$url = (($exp - 60 < time()) ? html_entity_decode($r['display_path'], ENT_QUOTES) : '');
if($url) {
// Get data from remote server
......@@ -316,7 +311,7 @@ function photocache_url(&$cache = array()) {
$oldsize = $r['filesize'];
if($orig_width >= $minres || $orig_height >= $minres) {
$path = 'store/[data]/[cache]/' . substr($r['xchan'],0,2) . '/' . substr($r['xchan'],2,2);
$path = 'store/[data]/[cache]/' . substr($r['xchan'],0,1) . '/' . substr($r['xchan'],1,1);
$os_path = $path . '/' . $r['xchan'];
$r['os_syspath'] = $os_path;
if(! is_dir($path))
......
<?php
namespace Zotlabs\Module;
use Zotlabs\Web\HTTPSig;
class Activity extends \Zotlabs\Web\Controller {
......@@ -47,9 +48,9 @@ class Activity extends \Zotlabs\Web\Controller {
$x['signature'] = \Zotlabs\Lib\LDSignatures::dopplesign($x,$chan);
$ret = json_encode($x, JSON_UNESCAPED_SLASHES);
$hash = \Zotlabs\Web\HTTPSig::generate_digest($ret,false);
$headers['Digest'] = 'SHA-256=' . $hash;
\Zotlabs\Web\HTTPSig::create_sig('',$headers,$chan['channel_prvkey'],z_root() . '/channel/' . $chan['channel_address'],true);
$headers['Digest'] = HTTPSig::generate_digest_header($ret);
$h = HTTPSig::create_sig($headers,$chan['channel_prvkey'],channel_url($chan));
HTTPSig::set_headers($h);
echo $ret;
killme();
......@@ -57,4 +58,4 @@ class Activity extends \Zotlabs\Web\Controller {
}
}
\ No newline at end of file
}
<?php
namespace Zotlabs\Module;
use Zotlabs\Web\HTTPSig;
require_once('include/zot.php');
require_once('library/jsonld/jsonld.php');
......@@ -32,7 +34,7 @@ class Ap_probe extends \Zotlabs\Web\Controller {
$o .= '<pre>' . htmlspecialchars($x['body']) . '</pre>' . EOL;
$o .= 'verify returns: ' . str_replace("\n",EOL,print_r(\Zotlabs\Web\HTTPSig::verify($x),true)) . EOL;
$o .= 'verify returns: ' . str_replace("\n",EOL,print_r(HTTPSig::verify($x),true)) . EOL;
$text = $x['body'];
}
else {
......
......@@ -2,6 +2,7 @@
namespace Zotlabs\Module;
use Zotlabs\Web\HTTPSig;
class Followers extends \Zotlabs\Web\Controller {
......@@ -44,12 +45,11 @@ class Followers extends \Zotlabs\Web\Controller {
$headers['Content-Type'] = 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"' ;
$x['signature'] = \Zotlabs\Lib\LDSignatures::dopplesign($x,$channel);
$ret = json_encode($x, JSON_UNESCAPED_SLASHES);
$hash = \Zotlabs\Web\HTTPSig::generate_digest($ret,false);
$headers['Digest'] = 'SHA-256=' . $hash;
\Zotlabs\Web\HTTPSig::create_sig('',$headers,$channel['channel_prvkey'],z_root() . '/channel/' . $channel['channel_address'],true);
$headers['Digest'] = HTTPSig::generate_digest_header($ret);
$h = HTTPSig::create_sig($headers,$channel['channel_prvkey'],channel_url($channel));
HTTPSig::set_headers($h);
echo $ret;
killme();
}
}
......
......@@ -2,6 +2,7 @@
namespace Zotlabs\Module;
use Zotlabs\Web\HTTPSig;
class Following extends \Zotlabs\Web\Controller {
......@@ -43,12 +44,11 @@ class Following extends \Zotlabs\Web\Controller {
$headers['Content-Type'] = 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"' ;
$x['signature'] = \Zotlabs\Lib\LDSignatures::dopplesign($x,$channel);
$ret = json_encode($x, JSON_UNESCAPED_SLASHES);
$hash = \Zotlabs\Web\HTTPSig::generate_digest($ret,false);
$headers['Digest'] = 'SHA-256=' . $hash;
\Zotlabs\Web\HTTPSig::create_sig('',$headers,$channel['channel_prvkey'],z_root() . '/channel/' . $channel['channel_address'],true);
$headers['Digest'] = HTTPSig::generate_digest_header($ret);
$h = HTTPSig::create_sig($headers,$channel['channel_prvkey'],channel_url($channel));
HTTPSig::set_headers($h);
echo $ret;
killme();
}
}
......
<?php
namespace Zotlabs\Module;
use Zotlabs\Web\HTTPSig;
class Inbox extends \Zotlabs\Web\Controller {
......@@ -14,23 +16,13 @@ class Inbox extends \Zotlabs\Web\Controller {
$sys_disabled = true;
}
$is_public = false;
if(argc() == 1 || argv(1) === '[public]') {
$is_public = true;
}
else {
$channels = [ channelx_by_nick(argv(1)) ];
}
$data = file_get_contents('php://input');
if(! $data)
return;
logger('inbox_activity: ' . jindent($data), LOGGER_DATA);
\Zotlabs\Web\HTTPSig::verify($data);
HTTPSig::verify($data);
$AS = new \Zotlabs\Lib\ActivityStreams($data);
......@@ -45,7 +37,7 @@ class Inbox extends \Zotlabs\Web\Controller {
if($AS->type == 'Update' && $AS->obj['type'] == 'Person') {
$x['recipient']['xchan_network'] = 'activitypub';
$x['recipient']['xchan_hash'] = $AS->obj['id'];
$x['recipient']['xchan_hash'] = $observer_hash;
pubcrawl_permissions_update($x);
return;
}
......@@ -79,20 +71,35 @@ class Inbox extends \Zotlabs\Web\Controller {
}
if($is_public) {
$is_public = false;
if(argc() == 1 || argv(1) === '[public]') {
$is_public = true;
}
else {
$channels = [ channelx_by_nick(argv(1)) ];
}
if($is_public) {
$parent = ((is_array($AS->obj) && array_key_exists('inReplyTo',$AS->obj)) ? urldecode($AS->obj['inReplyTo']) : '');
if($parent) {
//this is a comment - deliver to everybody who owns the parent
// this is a comment - deliver to everybody who owns the parent
$channels = q("SELECT * from channel where channel_id in ( SELECT uid from item where ( mid = '%s' OR mid = '%s' ) ) and channel_address != '%s'",
dbesc($parent),
dbesc(basename($parent)),
dbesc(str_replace(z_root() . '/channel/', '', $observer_hash))
);
// in case we receive a comment to a parent we do not have yet
// deliver to anybody following $AS->actor and let it fetch the parent
if(! $channels) {
$channels = q("SELECT * from channel where channel_id in ( SELECT abook_channel from abook left join xchan on abook_xchan = xchan_hash WHERE xchan_network = 'activitypub' and xchan_hash = '%s' ) and channel_removed = 0 ",
dbesc($observer_hash)
);
}
}
else {
// Pleroma sends follow activities to the publicInbox and therefore requires special handling.
if($AS->type === 'Follow' && $AS->obj && $AS->obj['type'] === 'Person') {
......@@ -102,7 +109,6 @@ class Inbox extends \Zotlabs\Web\Controller {
}
else {
// deliver to anybody following $AS->actor
$channels = q("SELECT * from channel where channel_id in ( SELECT abook_channel from abook left join xchan on abook_xchan = xchan_hash WHERE xchan_network = 'activitypub' and xchan_hash = '%s' ) and channel_removed = 0 ",
dbesc($observer_hash)
);
......@@ -193,12 +199,15 @@ class Inbox extends \Zotlabs\Web\Controller {
break;
}
case 'Delete':
as_delete_action($channel,$observer_hash,$AS);
break;
case 'Add':
case 'Remove':
break;
case 'Announce':
as_announce_action($channel,$observer_hash,$AS);
as_create_action($channel,$observer_hash,$AS);
//as_announce_action($channel,$observer_hash,$AS);
break;
default:
break;
......
<?php
namespace Zotlabs\Module;
use Zotlabs\Web\HTTPSig;
class Outbox extends \Zotlabs\Web\Controller {
......@@ -66,9 +67,9 @@ class Outbox extends \Zotlabs\Web\Controller {
$headers['Content-Type'] = 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"' ;
$x['signature'] = \Zotlabs\Lib\LDSignatures::dopplesign($x,$channel);
$ret = json_encode($x, JSON_UNESCAPED_SLASHES);
$hash = \Zotlabs\Web\HTTPSig::generate_digest($ret,false);
$headers['Digest'] = 'SHA-256=' . $hash;
\Zotlabs\Web\HTTPSig::create_sig('',$headers,$channel['channel_prvkey'],z_root() . '/channel/' . $channel['channel_address'],true);
$headers['Digest'] = HTTPSig::generate_digest_header($ret);
$h = HTTPSig::create_sig($headers,$channel['channel_prvkey'],channel_url($channel));
HTTPSig::set_headers($h);
echo $ret;
killme();
......
This diff is collapsed.
This diff is collapsed.
......@@ -30,6 +30,10 @@ class Queueworker extends Controller {
$maxworkerage = ($maxworkerage > 100) ? $maxworkerage : 300;
set_config('queueworker','queueworker_max_age',$maxworkerage);
$queueworkersleep = intval($_POST['queue_worker_sleep']);
$queueworkersleep = ($queueworkersleep > 100) ? $queueworkersleep : 100;
set_config('queueworker','queue_worker_sleep',$queueworkersleep);
goaway(z_root().'/queueworker');
}
......@@ -91,6 +95,19 @@ class Queueworker extends Controller {
]
]);
$queueworkersleep = get_config('queueworker','queue_worker_sleep');
$queueworkersleep = ($queueworkersleep > 100) ? $queueworkersleep : 100;
set_config('queueworker','queue_worker_sleep',$queueworkersleep);
$sc .= replace_macros(get_markup_template('field_input.tpl'), [
'$field' => [
'queue_worker_sleep',
t('Pause before starting next task: (microseconds. Minimum 100 = .0001 seconds)'),
$queueworkersleep,
'',
$paths
]
]);
$tpl = get_markup_template('settings_addon.tpl');
$content .= replace_macros($tpl, [
......
......@@ -6,18 +6,21 @@ use Zotlabs\Extend\Hook;
/**
* Name: queueworker
* Description: EXPERIMENTAL Queue work queue for backgrounded tasks
* Version: 0.2.0
* Description: Next generation queue worker for backgrounded tasks (BETA)
* Version: 0.8.0
* Author: Matthew Dent <dentm42@dm42.net>
* MinVersion: 3.8.7
* MinVersion: 4.2.1
*/
class QueueWorkerUtils {
public static $queueworker_version = '0.2.0';
public static $hubzilla_minver = '3.8.7';
public static $queueworker_version = '0.8.0';
public static $hubzilla_minver = '4.2.1';
public static $queueworker_dbver = 1;
public static $queueworker = null;
public static $maxworkers = 0;
public static $workermaxage = 0;
public static $workersleep = 100;
public static function check_min_version ($platform,$minver) {
switch ($platform) {
......@@ -124,7 +127,7 @@ class QueueWorkerUtils {
foreach ($sql as $query) {
$r = q($query);
if (!$r) {
logger ('dbUpgrade/Install Error (query): '.$query);
logger ('dbUpgrade/Install Error (query): '.$query,LOGGER_NORMAL);
return UPDATE_FAILED;
}
}
......@@ -237,35 +240,92 @@ class QueueWorkerUtils {
return;
}
public static function MasterRelease(&$arr) {
public static function MasterSummon(&$arr) {
$argv=$arr['argv'];
$argc=count($argv);
if ($argv[0]!='Queueworker') {
$priority = 0; //Default priority @TODO allow reprioritization
$priority = 0; //Default priority @TODO allow reprioritization
$workinfo = ['argc'=>$argc,'argv'=>$argv];
$r = q("select * from workerq where workerq_data = '%s'",
dbesc(self::maybejson($workerinfo)));
if ($r) {
logger("Ignoring duplicate workerq task",LOGGER_DEBUG);
return;
}
self::qbegin('workerq');
$r = q("insert into workerq (workerq_priority,workerq_data) values (%d,'%s')",
intval($priority),
dbesc(self::maybejson($workinfo)));
self::qcommit();
if (!$r) {
logger("INSERT FAILED",LOGGER_DEBUG);
return;
}
logger('INSERTED: '.self::maybejson($workinfo),LOGGER_DEBUG);
}
$argv=[];
$arr=['argv'=>$argv];
$workers=self::GetWorkerCount();
if ($workers < self::$maxworkers) {
logger("Less than max active workers ($workers) max = ".self::$maxworkers.".",LOGGER_DEBUG);
$phpbin = get_config('system','phpbin','php');
proc_run($phpbin,'Zotlabs/Daemon/Master.php',['Queueworker']);
}
}
$workinfo = ['argc'=>$argc,'argv'=>$argv];
public static function MasterRelease(&$arr) {
$r = q("select * from workerq where workerq_data = '%s'",
dbesc(self::maybejson($workerinfo)));
if ($r) {
logger("Ignoring duplicate workerq task");
return;
}
$argv=$arr['argv'];
$argc=count($argv);
if ($argv[0] != 'Queueworker') {
$priority = 0; //Default priority @TODO allow reprioritization
self::qbegin('workerq');
$r = q("insert into workerq (workerq_priority,workerq_data) values (%d,'%s')",
intval($priority),
dbesc(self::maybejson($workinfo)));
self::qcommit();
if (!$r) {
logger("INSERT FAILED");
return;
$workinfo = ['argc'=>$argc,'argv'=>$argv];
$r = q("select * from workerq where workerq_data = '%s'",
dbesc(self::maybejson($workerinfo)));
if (!$r) {
self::qbegin('workerq');
$r = q("insert into workerq (workerq_priority,workerq_data) values (%d,'%s')",
intval($priority),
dbesc(self::maybejson($workinfo)));
self::qcommit();
if (!$r) {
logger("Insert failed: ".json_encode($workinfo),LOGGER_DEBUG);
return;
}
logger('INSERTED: '.self::maybejson($workinfo),LOGGER_DEBUG);
} else {
logger("Duplicate task - do not insert.",LOGGER_DEBUG);
}
}
logger('INSERTED: '.self::maybejson($workinfo),LOGGER_DEBUG);
$argv=[];
$arr=['argv'=>$argv];
self::Process();
self::Process();
}
static public function GetWorkerCount() {
if (self::$maxworkers == 0) {
self::$maxworkers = get_config('queueworker','max_queueworkers',4);
self::$maxworkers = (self::$maxworkers > 3) ? self::$maxworkers : 4;
}
if (self::$workermaxage == 0) {
self::$workermaxage = get_config('queueworker','max_queueworker_age');
self::$workermaxage = (self::$workermaxage > 120) ? self::$workermaxage : 300;
}
q("update workerq set workerq_reservationid = null where workerq_processtimeout < %s", db_utcnow());
usleep(self::$workersleep);
$workers = q("select distinct workerq_reservationid from workerq");
$workers = isset($workers) ? intval(count($workers)) : 1;
logger("WORKERCOUNT: $workers",LOGGER_DEBUG);
return intval($workers);
}
static public function GetWorkerID() {
......@@ -273,27 +333,22 @@ class QueueWorkerUtils {
return self::$queueworker;
}
$maxworkers = get_config('queueworker','max_queueworkers',4);
$maxworkers = ($maxworkers > 3) ? $maxworkers : 4;
$workermaxage = get_config('queueworker','max_queueworker_age');
$workermaxage = ($workermaxage > 120) ? $workermaxage : 300;
$wid = uniqid('',true);
q("update workerq set workerq_reservationid = null where workerq_processtimeout < %s", db_utcnow());
$workers = q("select distinct workerq_reservationid from workerq");
if (count($workers) > $maxworkers) {
logger("Too many active workers",LOGGER_DEBUG);
usleep(mt_rand(500000,3000000)); //Sleep .5 - 3 seconds before creating a new worker.
$workers = self::GetWorkerCount();
if ($workers >= self::$maxworkers) {
logger("Too many active workers ($workers) max = ".self::$maxworkers,LOGGER_DEBUG);
return false;
}
self::$queueworker=$wid;
self::$queueworker = $wid;
return $wid;
}
static private function getworkid() {
$workermaxage = get_config('queueworker','max_queueworker_age');
$workermaxage = ($workermaxage > 120) ? $workermaxage : 300;
self::GetWorkerCount();
self::qbegin('workerq');
$work = q("select workerq_id from workerq
......@@ -309,31 +364,32 @@ class QueueWorkerUtils {
$work = q("update workerq set workerq_reservationid='%s', workerq_processtimeout = %s + interval %s where workerq_id = %d",
self::$queueworker,