8 public function __construct()
16 $result = $this->cliParser->parse();
17 } catch (\Exception $exc) {
18 $this->cliParser->displayError($exc->getMessage());
22 if ($result->options['debug']) {
27 $deps = new Dependencies();
29 $GLOBALS['dbdsn'], $GLOBALS['dbuser'], $GLOBALS['dbpass']
32 $deps->options = array_merge(
34 $result->command ? $result->command->options : array(),
35 ($result->command && $result->command->command)
36 ? $result->command->command->options
40 if ($result->command_name == 'feed') {
41 $this->runFeed($result->command, $deps);
42 } else if ($result->command_name == 'handle') {
43 $this->runPingbackHandler($result->command, $deps);
45 $this->cliParser->displayUsage(1);
47 } catch (\Exception $e) {
48 $msg = 'stapibas exception!' . "\n"
49 . 'Code: ' . $e->getCode() . "\n"
50 . 'Message: ' . $e->getMessage() . "\n";
51 file_put_contents('php://stderr', $msg);
56 protected function runFeed(
57 \Console_CommandLine_Result $command, Dependencies $deps
59 if ($command->command_name == 'update') {
60 return $this->runFeedUpdate($command, $deps);
63 $mg = new Feed_Manage($deps);
64 if ($command->command_name == 'add') {
65 $mg->addFeed($command->command->args['feed']);
66 } else if ($command->command_name == 'remove') {
67 $mg->removeFeed($command->command->args['feed']);
73 protected function runFeedUpdate(
74 \Console_CommandLine_Result $result, Dependencies $deps
76 $tasks = array_flip(explode(',', $result->command->options['tasks']));
78 if (isset($tasks['feeds'])) {
79 $this->runFeedUpdateFeeds($deps);
81 if (isset($tasks['entries'])) {
82 $this->runFeedUpdateEntries($deps);
84 if (isset($tasks['urls'])) {
85 $this->runFeedUpdatePingUrls($deps);
90 protected function runFeedUpdateFeeds($deps)
92 $uf = new Feed_UpdateFeeds($deps);
93 if ($deps->options['feed'] === null) {
96 $urlOrIds = explode(',', $deps->options['feed']);
97 $uf->updateSome($urlOrIds);
101 protected function runFeedUpdateEntries($deps)
103 $ue = new Feed_UpdateEntries($deps);
104 if ($deps->options['entry'] === null) {
107 $urlOrIds = explode(',', $deps->options['entry']);
108 $ue->updateSome($urlOrIds);
112 protected function runFeedUpdatePingUrls($deps)
114 $uf = new Feed_PingUrls($deps);
115 if ($deps->options['entryurl'] === null) {
118 $urls = explode(',', $deps->options['entryurl']);
119 $uf->pingSome($urls);
124 protected function runPingbackHandler(
125 \Console_CommandLine_Result $command, Dependencies $deps
131 public function setupCli()
133 $p = new \Console_CommandLine();
134 $p->description = 'Sends pingbacks to URLs linked in Atom feed entries';
135 $p->version = '0.0.1';
140 'short_name' => '-d',
141 'long_name' => '--debug',
142 'description' => "Output debug messages",
143 'action' => 'StoreTrue'
149 'short_name' => '-f',
150 'long_name' => '--force',
151 'description' => "Update even when resource did not change",
152 'action' => 'StoreTrue'
156 $this->setupCliFeed($p);
157 $this->setupCliPingback($p);
159 $this->cliParser = $p;
162 protected function setupCliFeed($p)
164 $feed = $p->addCommand(
167 'description' => 'Edit, list or delete feeds'
171 $add = $feed->addCommand(
174 'description' => 'Add the feed',
177 $add->addArgument('feed', array('description' => 'URL of feed'));
179 $remove = $feed->addCommand(
182 'description' => 'Remove the feed',
185 $remove->addArgument('feed', array('description' => 'URL or ID of feed'));
188 $update = $feed->addCommand(
191 'description' => 'Update feed data and send out pings'
197 'short_name' => '-i',
198 'long_name' => '--feed',
199 'description' => 'Update this feed URL or ID',
200 'help_name' => 'URL|ID',
201 'action' => 'StoreString'
207 'short_name' => '-e',
208 'long_name' => '--entry',
209 'description' => 'Update this feed entry URL or ID',
210 'help_name' => 'URL|ID',
211 'action' => 'StoreString'
217 'short_name' => '-t',
218 'long_name' => '--tasks',
219 'description' => 'Execute the given tasks (comma-separated: feeds,entries,urls)',
220 'help_name' => 'tasks',
221 'action' => 'StoreString',
222 'default' => 'feeds,entries,urls',
228 'long_name' => '--list-tasks',
229 'description' => 'Show all possible tasks',
231 'action_params' => array(
232 'list' => array('feeds', 'entries', 'urls')
239 'short_name' => '-u',
240 'long_name' => '--url',
241 'description' => 'Ping this URL or ID',
242 'help_name' => 'URL|ID',
243 'action' => 'StoreString'
248 protected function setupCliPingback($p)
250 $handle = $p->addCommand(
253 'description' => 'Handle pingbacks: Fetch content, extract data'