[DAEMONS][TwitterBridge] Set PUBLICDIR

This commit is contained in:
Alexei Sorokin 2019-11-01 15:27:36 +03:00 committed by Diogo Peralta Cordeiro
parent ab020c7528
commit 0c1e9bbc17
3 changed files with 104 additions and 87 deletions

View File

@ -1,24 +1,27 @@
#!/usr/bin/env php #!/usr/bin/env php
<?php <?php
/* // This file is part of GNU social - https://www.gnu.org/software/social
* StatusNet - the distributed open-source microblogging tool //
* Copyright (C) 2008, 2009, StatusNet, Inc. // GNU social is free software: you can redistribute it and/or modify
* // it under the terms of the GNU Affero General Public License as published by
* This program is free software: you can redistribute it and/or modify // the Free Software Foundation, either version 3 of the License, or
* it under the terms of the GNU Affero General Public License as published by // (at your option) any later version.
* the Free Software Foundation, either version 3 of the License, or //
* (at your option) any later version. // GNU social is distributed in the hope that it will be useful,
* // but WITHOUT ANY WARRANTY; without even the implied warranty of
* This program is distributed in the hope that it will be useful, // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* but WITHOUT ANY WARRANTY; without even the implied warranty of // GNU Affero General Public License for more details.
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
* GNU Affero General Public License for more details. // You should have received a copy of the GNU Affero General Public License
* // along with GNU social. If not, see <http://www.gnu.org/licenses/>.
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. /**
* @copyright 2008, 2009 StatusNet, Inc
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
*/ */
define('INSTALLDIR', realpath(dirname(__FILE__) . '/../../..')); define('INSTALLDIR', realpath(dirname(__FILE__) . '/../../..'));
define('PUBLICDIR', INSTALLDIR . DIRECTORY_SEPARATOR . 'public');
$shortoptions = 'di::'; $shortoptions = 'di::';
$longoptions = array('id::', 'debug'); $longoptions = array('id::', 'debug');
@ -56,9 +59,12 @@ class SyncTwitterFriendsDaemon extends ParallelizingDaemon
* @return void * @return void
* *
**/ **/
function __construct($id = null, $interval = 60, public function __construct(
$max_children = 2, $debug = null) $id = null,
{ $interval = 60,
$max_children = 2,
$debug = null
) {
parent::__construct($id, $interval, $max_children, $debug); parent::__construct($id, $interval, $max_children, $debug);
} }
@ -67,7 +73,7 @@ class SyncTwitterFriendsDaemon extends ParallelizingDaemon
* *
* @return string Name of the daemon. * @return string Name of the daemon.
*/ */
function name() public function name()
{ {
return ('synctwitterfriends.' . $this->_id); return ('synctwitterfriends.' . $this->_id);
} }
@ -78,7 +84,7 @@ class SyncTwitterFriendsDaemon extends ParallelizingDaemon
* *
* @return array flinks an array of Foreign_link objects * @return array flinks an array of Foreign_link objects
*/ */
function getObjects() public function getObjects()
{ {
$flinks = array(); $flinks = array();
$flink = new Foreign_link(); $flink = new Foreign_link();
@ -105,7 +111,8 @@ class SyncTwitterFriendsDaemon extends ParallelizingDaemon
} }
// FIXME: make it so we can force a Foreign_link here without colliding with parent // FIXME: make it so we can force a Foreign_link here without colliding with parent
function childTask($flink) { public function childTask($flink)
{
// Each child ps needs its own DB connection // Each child ps needs its own DB connection
// Note: DataObject::getDatabaseConnection() creates // Note: DataObject::getDatabaseConnection() creates
@ -125,7 +132,7 @@ class SyncTwitterFriendsDaemon extends ParallelizingDaemon
unset($_DB_DATAOBJECT['CONNECTIONS']); unset($_DB_DATAOBJECT['CONNECTIONS']);
} }
function fetchTwitterFriends(Foreign_link $flink) public function fetchTwitterFriends(Foreign_link $flink)
{ {
$friends = array(); $friends = array();
@ -168,15 +175,17 @@ class SyncTwitterFriendsDaemon extends ParallelizingDaemon
} }
for ($i = 1; $i <= $pages; $i++) { for ($i = 1; $i <= $pages; $i++) {
try {
try { $more_friends = $client->statusesFriends(null, null, null, $i);
$more_friends = $client->statusesFriends(null, null, null, $i); } catch (Exception $e) {
} catch (Exception $e) { common_log(
common_log(LOG_WARNING, $this->name() . LOG_WARNING,
' - cURL error getting Twitter statuses/friends ' . $this->name() .
"page $i - " . $e->getCode() . ' - ' . ' - cURL error getting Twitter statuses/friends ' .
$e->getMessage()); "page {$i} - " . $e->getCode() . ' - ' .
} $e->getMessage()
);
}
if (empty($more_friends)) { if (empty($more_friends)) {
common_log(LOG_WARNING, $this->name() . common_log(LOG_WARNING, $this->name() .
@ -193,7 +202,7 @@ class SyncTwitterFriendsDaemon extends ParallelizingDaemon
return $friends; return $friends;
} }
function subscribeTwitterFriends(Foreign_link $flink) public function subscribeTwitterFriends(Foreign_link $flink)
{ {
try { try {
$profile = $flink->getProfile(); $profile = $flink->getProfile();
@ -211,7 +220,6 @@ class SyncTwitterFriendsDaemon extends ParallelizingDaemon
} }
foreach ($friends as $friend) { foreach ($friends as $friend) {
$friend_name = $friend->screen_name; $friend_name = $friend->screen_name;
$friend_id = (int) $friend->id; $friend_id = (int) $friend->id;
@ -232,9 +240,11 @@ class SyncTwitterFriendsDaemon extends ParallelizingDaemon
$friend_profile = $friend_flink->getProfile(); $friend_profile = $friend_flink->getProfile();
Subscription::start($profile, $friend_profile); Subscription::start($profile, $friend_profile);
common_log(LOG_INFO, common_log(
$this->name() . ' - Subscribed ' . LOG_INFO,
"{$friend_profile->nickname} to {$profile->nickname}."); $this->name() . ' - Subscribed ' .
"{$friend_profile->nickname} to {$profile->nickname}."
);
} catch (NoResultException $e) { } catch (NoResultException $e) {
// either no foreign link for this friend's foreign ID or no profile found on local ID. // either no foreign link for this friend's foreign ID or no profile found on local ID.
} catch (Exception $e) { } catch (Exception $e) {
@ -247,7 +257,6 @@ class SyncTwitterFriendsDaemon extends ParallelizingDaemon
return true; return true;
} }
} }
$id = null; $id = null;
@ -255,9 +264,9 @@ $debug = null;
if (have_option('i')) { if (have_option('i')) {
$id = get_option_value('i'); $id = get_option_value('i');
} else if (have_option('--id')) { } elseif (have_option('--id')) {
$id = get_option_value('--id'); $id = get_option_value('--id');
} else if (count($args) > 0) { } elseif (count($args) > 0) {
$id = $args[0]; $id = $args[0];
} else { } else {
$id = null; $id = null;

View File

@ -1,24 +1,27 @@
#!/usr/bin/env php #!/usr/bin/env php
<?php <?php
/* // This file is part of GNU social - https://www.gnu.org/software/social
* StatusNet - the distributed open-source microblogging tool //
* Copyright (C) 2008-2010, StatusNet, Inc. // GNU social is free software: you can redistribute it and/or modify
* // it under the terms of the GNU Affero General Public License as published by
* This program is free software: you can redistribute it and/or modify // the Free Software Foundation, either version 3 of the License, or
* it under the terms of the GNU Affero General Public License as published by // (at your option) any later version.
* the Free Software Foundation, either version 3 of the License, or //
* (at your option) any later version. // GNU social is distributed in the hope that it will be useful,
* // but WITHOUT ANY WARRANTY; without even the implied warranty of
* This program is distributed in the hope that it will be useful, // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* but WITHOUT ANY WARRANTY; without even the implied warranty of // GNU Affero General Public License for more details.
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
* GNU Affero General Public License for more details. // You should have received a copy of the GNU Affero General Public License
* // along with GNU social. If not, see <http://www.gnu.org/licenses/>.
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. /**
* @copyright 2008-2010 StatusNet, Inc
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
*/ */
define('INSTALLDIR', realpath(dirname(__FILE__) . '/../../..')); define('INSTALLDIR', realpath(dirname(__FILE__) . '/../../..'));
define('PUBLICDIR', INSTALLDIR . DIRECTORY_SEPARATOR . 'public');
$shortoptions = 'fi::a'; $shortoptions = 'fi::a';
$longoptions = array('id::', 'foreground', 'all'); $longoptions = array('id::', 'foreground', 'all');
@ -39,7 +42,7 @@ class TwitterDaemon extends SpawningDaemon
{ {
protected $allsites = false; protected $allsites = false;
function __construct($id=null, $daemonize=true, $threads=1, $allsites=false) public function __construct($id = null, $daemonize = true, $threads = 1, $allsites = false)
{ {
if ($threads != 1) { if ($threads != 1) {
// This should never happen. :) // This should never happen. :)
@ -49,7 +52,7 @@ class TwitterDaemon extends SpawningDaemon
$this->allsites = $allsites; $this->allsites = $allsites;
} }
function runThread() public function runThread()
{ {
common_log(LOG_INFO, 'Waiting to listen to Twitter and queues'); common_log(LOG_INFO, 'Waiting to listen to Twitter and queues');
@ -61,14 +64,13 @@ class TwitterDaemon extends SpawningDaemon
return $master->respawn ? self::EXIT_RESTART : self::EXIT_SHUTDOWN; return $master->respawn ? self::EXIT_RESTART : self::EXIT_SHUTDOWN;
} }
} }
class TwitterMaster extends IoMaster class TwitterMaster extends IoMaster
{ {
protected $processManager; protected $processManager;
function __construct($id, $processManager) public function __construct($id, $processManager)
{ {
parent::__construct($id); parent::__construct($id);
$this->processManager = $processManager; $this->processManager = $processManager;
@ -78,7 +80,7 @@ class TwitterMaster extends IoMaster
* Initialize IoManagers for the currently configured site * Initialize IoManagers for the currently configured site
* which are appropriate to this instance. * which are appropriate to this instance.
*/ */
function initManagers() public function initManagers()
{ {
$qm = QueueManager::get(); $qm = QueueManager::get();
$qm->setActiveGroup('twitter'); $qm->setActiveGroup('twitter');
@ -298,7 +300,7 @@ class TwitterManager extends IoManager
if (have_option('i', 'id')) { if (have_option('i', 'id')) {
$id = get_option_value('i', 'id'); $id = get_option_value('i', 'id');
} else if (count($args) > 0) { } elseif (count($args) > 0) {
$id = $args[0]; $id = $args[0];
} else { } else {
$id = null; $id = null;

View File

@ -1,24 +1,27 @@
#!/usr/bin/env php #!/usr/bin/env php
<?php <?php
// This file is part of GNU social - https://www.gnu.org/software/social
//
// GNU social is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// GNU social is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with GNU social. If not, see <http://www.gnu.org/licenses/>.
/** /**
* StatusNet - the distributed open-source microblogging tool * @copyright 2008-2010 StatusNet, Inc
* Copyright (C) 2008-2010, StatusNet, Inc. * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
define('INSTALLDIR', realpath(dirname(__FILE__) . '/../../..')); define('INSTALLDIR', realpath(dirname(__FILE__) . '/../../..'));
define('PUBLICDIR', INSTALLDIR . DIRECTORY_SEPARATOR . 'public');
// Tune number of processes and how often to poll Twitter // Tune number of processes and how often to poll Twitter
// XXX: Should these things be in config.php? // XXX: Should these things be in config.php?
@ -74,9 +77,12 @@ class TwitterStatusFetcher extends ParallelizingDaemon
* @return void * @return void
* *
**/ **/
function __construct($id = null, $interval = 60, public function __construct(
$max_children = 2, $debug = null) $id = null,
{ $interval = 60,
$max_children = 2,
$debug = null
) {
parent::__construct($id, $interval, $max_children, $debug); parent::__construct($id, $interval, $max_children, $debug);
} }
@ -85,7 +91,7 @@ class TwitterStatusFetcher extends ParallelizingDaemon
* *
* @return string Name of the daemon. * @return string Name of the daemon.
*/ */
function name() public function name()
{ {
return ('twitterstatusfetcher.'.$this->_id); return ('twitterstatusfetcher.'.$this->_id);
} }
@ -96,7 +102,7 @@ class TwitterStatusFetcher extends ParallelizingDaemon
* *
* @return array flinks an array of Foreign_link objects * @return array flinks an array of Foreign_link objects
*/ */
function getObjects() public function getObjects()
{ {
global $_DB_DATAOBJECT; global $_DB_DATAOBJECT;
$flink = new Foreign_link(); $flink = new Foreign_link();
@ -109,7 +115,6 @@ class TwitterStatusFetcher extends ParallelizingDaemon
$flinks = array(); $flinks = array();
while ($flink->fetch()) { while ($flink->fetch()) {
if (($flink->noticesync & FOREIGN_NOTICE_RECV) == if (($flink->noticesync & FOREIGN_NOTICE_RECV) ==
FOREIGN_NOTICE_RECV) { FOREIGN_NOTICE_RECV) {
$flinks[] = clone($flink); $flinks[] = clone($flink);
@ -129,7 +134,8 @@ class TwitterStatusFetcher extends ParallelizingDaemon
} }
// FIXME: make it so we can force a Foreign_link here without colliding with parent // FIXME: make it so we can force a Foreign_link here without colliding with parent
function childTask($flink) { public function childTask($flink)
{
// Each child ps needs its own DB connection // Each child ps needs its own DB connection
// Note: DataObject::getDatabaseConnection() creates // Note: DataObject::getDatabaseConnection() creates
@ -150,7 +156,7 @@ class TwitterStatusFetcher extends ParallelizingDaemon
unset($_DB_DATAOBJECT['CONNECTIONS']); unset($_DB_DATAOBJECT['CONNECTIONS']);
} }
function getTimeline(Foreign_link $flink, $timelineUri = 'home_timeline') public function getTimeline(Foreign_link $flink, $timelineUri = 'home_timeline')
{ {
common_log(LOG_DEBUG, $this->name() . ' - Trying to get ' . $timelineUri . common_log(LOG_DEBUG, $this->name() . ' - Trying to get ' . $timelineUri .
' timeline for Twitter user ' . $flink->foreign_id); ' timeline for Twitter user ' . $flink->foreign_id);
@ -219,9 +225,9 @@ $debug = null;
if (have_option('i')) { if (have_option('i')) {
$id = get_option_value('i'); $id = get_option_value('i');
} else if (have_option('--id')) { } elseif (have_option('--id')) {
$id = get_option_value('--id'); $id = get_option_value('--id');
} else if (count($args) > 0) { } elseif (count($args) > 0) {
$id = $args[0]; $id = $args[0];
} else { } else {
$id = null; $id = null;