1
0
Fork 0

modded scripts to be runned in cli so they can be included and executed in main program

This commit is contained in:
Fabio Comuni 2011-01-28 14:04:18 +01:00
parent 517d6812da
commit ef33ca6750
4 changed files with 88 additions and 50 deletions

View file

@ -1,14 +1,19 @@
<?php <?php
require_once("boot.php");
require_once("boot.php"); function directory_run($argv, $argc){
global $a, $db;
$a = new App;
@include(".htconfig.php");
require_once("dba.php");
$db = new dba($db_host, $db_user, $db_pass, $db_data);
unset($db_host, $db_user, $db_pass, $db_data);
if(is_null($a)){
$a = new App;
}
if(is_null($db)){
@include(".htconfig.php");
require_once("dba.php");
$db = new dba($db_host, $db_user, $db_pass, $db_data);
unset($db_host, $db_user, $db_pass, $db_data);
};
if($argc != 2) if($argc != 2)
return; return;
@ -20,9 +25,14 @@
$dir = get_config('system','directory_submit_url'); $dir = get_config('system','directory_submit_url');
if(! strlen($dir)) if(! strlen($dir))
exit; return;
fetch_url($dir . '?url=' . bin2hex($argv[1])); fetch_url($dir . '?url=' . bin2hex($argv[1]));
return; return;
}
if (array_search(__file__,get_included_files())===0){
directory_run($argv,$argc);
killme();
}

View file

@ -1,14 +1,19 @@
<?php <?php
require_once("boot.php");
require_once("boot.php"); function notifier_run($argv, $argc){
global $a, $db;
$a = new App;
@include(".htconfig.php");
require_once("dba.php");
$db = new dba($db_host, $db_user, $db_pass, $db_data);
unset($db_host, $db_user, $db_pass, $db_data);
if(is_null($a)){
$a = new App;
}
if(is_null($db)){
@include(".htconfig.php");
require_once("dba.php");
$db = new dba($db_host, $db_user, $db_pass, $db_data);
unset($db_host, $db_user, $db_pass, $db_data);
};
require_once("session.php"); require_once("session.php");
require_once("datetime.php"); require_once("datetime.php");
@ -30,7 +35,7 @@
default: default:
$item_id = intval($argv[2]); $item_id = intval($argv[2]);
if(! $item_id){ if(! $item_id){
killme(); return; return;
} }
break; break;
} }
@ -44,7 +49,7 @@
intval($item_id) intval($item_id)
); );
if(! count($message)){ if(! count($message)){
killme(); return; return;
} }
$uid = $message[0]['uid']; $uid = $message[0]['uid'];
$recipients[] = $message[0]['contact-id']; $recipients[] = $message[0]['contact-id'];
@ -52,15 +57,15 @@
} }
else { else {
// find ancestors
// find ancestors
$r = q("SELECT `parent`, `uid`, `edited` FROM `item` WHERE `id` = %d LIMIT 1", $r = q("SELECT `parent`, `uid`, `edited` FROM `item` WHERE `id` = %d LIMIT 1",
intval($item_id) intval($item_id)
); );
if(! count($r)){ if(! count($r)){
killme(); return; return;
} }
$parent_id = $r[0]['parent']; $parent_id = $r[0]['parent'];
$uid = $r[0]['uid']; $uid = $r[0]['uid'];
$updated = $r[0]['edited']; $updated = $r[0]['edited'];
@ -70,7 +75,7 @@
); );
if(! count($items)){ if(! count($items)){
killme(); return; return;
} }
} }
@ -83,7 +88,7 @@
if(count($r)) if(count($r))
$owner = $r[0]; $owner = $r[0];
else { else {
killme(); return; return;
} }
$hub = get_config('system','huburl'); $hub = get_config('system','huburl');
@ -155,7 +160,7 @@
$r = q("SELECT * FROM `contact` WHERE `id` IN ( $conversant_str ) AND `blocked` = 0 AND `pending` = 0"); $r = q("SELECT * FROM `contact` WHERE `id` IN ( $conversant_str ) AND `blocked` = 0 AND `pending` = 0");
if( ! count($r)){ if( ! count($r)){
killme(); return; return;
} }
$contacts = $r; $contacts = $r;
@ -254,7 +259,7 @@
dbesc($recip_str) dbesc($recip_str)
); );
if(! count($r)){ if(! count($r)){
killme(); return; return;
} }
// delivery loop // delivery loop
@ -365,5 +370,11 @@
} }
} }
killme(); return;
}
if (array_search(__file__,get_included_files())===0){
echo "run!";
notifier_run($argv,$argc);
killme();
}

View file

@ -1,14 +1,19 @@
<?php <?php
require_once("boot.php");
function poller_run($argv, $argc){
global $a, $db;
require_once('boot.php'); if(is_null($a)){
$a = new App;
$a = new App; }
@include('.htconfig.php'); if(is_null($db)){
require_once('dba.php'); @include(".htconfig.php");
$db = new dba($db_host, $db_user, $db_pass, $db_data); require_once("dba.php");
unset($db_host, $db_user, $db_pass, $db_data); $db = new dba($db_host, $db_user, $db_pass, $db_data);
unset($db_host, $db_user, $db_pass, $db_data);
};
require_once('session.php'); require_once('session.php');
require_once('datetime.php'); require_once('datetime.php');
@ -48,7 +53,7 @@
AND `self` = 0 AND `blocked` = 0 AND `readonly` = 0 ORDER BY RAND()"); AND `self` = 0 AND `blocked` = 0 AND `readonly` = 0 ORDER BY RAND()");
if(! count($contacts)){ if(! count($contacts)){
killme(); return; return;
} }
foreach($contacts as $contact) { foreach($contacts as $contact) {
@ -267,7 +272,10 @@
// loop - next contact // loop - next contact
} }
killme(); return;
}
if (array_search(__file__,get_included_files())===0){
poller_run($argv,$argc);
killme();
}

View file

@ -1,5 +1,5 @@
<?php <?php
require_once("boot.php");
function update_queue_time($id) { function update_queue_time($id) {
logger('queue: requeue item ' . $id); logger('queue: requeue item ' . $id);
@ -16,14 +16,19 @@ function remove_queue_item($id) {
); );
} }
require_once("boot.php"); function queue_run($argv, $argc){
global $a, $db;
$a = new App; if(is_null($a)){
$a = new App;
@include(".htconfig.php"); }
require_once("dba.php");
$db = new dba($db_host, $db_user, $db_pass, $db_data); if(is_null($db)){
unset($db_host, $db_user, $db_pass, $db_data); @include(".htconfig.php");
require_once("dba.php");
$db = new dba($db_host, $db_user, $db_pass, $db_data);
unset($db_host, $db_user, $db_pass, $db_data);
};
require_once("session.php"); require_once("session.php");
@ -51,7 +56,7 @@ function remove_queue_item($id) {
$r = q("SELECT `id` FROM `queue` WHERE `last` < UTC_TIMESTAMP() - INTERVAL 15 MINUTE "); $r = q("SELECT `id` FROM `queue` WHERE `last` < UTC_TIMESTAMP() - INTERVAL 15 MINUTE ");
if(! count($r)){ if(! count($r)){
killme(); return; return;
} }
// delivery loop // delivery loop
@ -118,7 +123,11 @@ function remove_queue_item($id) {
} }
} }
killme(); return;
// NOTREACHED }
if (array_search(__file__,get_included_files())===0){
queue_run($argv,$argc);
killme();
}