diff --git a/app/Commands/AdminLogsCommand.php b/app/Commands/AdminLogsCommand.php new file mode 100644 index 0000000..bc8af37 --- /dev/null +++ b/app/Commands/AdminLogsCommand.php @@ -0,0 +1,91 @@ +askText(); + $result = $input->ask(); + + $menu->redraw(); + }; + + return $callable; + } + + /** + * + * + */ + private function addCreateItem() + { + $menu = function(CliMenuBuilder $builder) + { + $data = []; + + $builder + ->setTitle('Settings > Add') + ->disableDefaultItems() + + // input name + ->addItem('name', $this->addInputItem()) + + // input url + ->addItem('url', $this->addInputItem()) + ->addItem('handler', $this->addInputItem()) + + ->addLineBreak('-') + ->addSubMenu('actions', $this->addActions()) + + ->addLineBreak('-'); + }; + + return $menu; + } + + /** + * Execute the console command. + * + * @return mixed + */ + public function handle() + { + // create menu + $builder = $this->menu('Settings'); + + $builder + ->addSubMenu('Add', $this->addCreateItem()) + ->addLineBreak('-'); + + $mainmenu = $builder->build(); + $mainmenu->open(); + } +} diff --git a/app/Commands/AdminSourcesCommand.php b/app/Commands/AdminSourcesCommand.php new file mode 100644 index 0000000..483ccef --- /dev/null +++ b/app/Commands/AdminSourcesCommand.php @@ -0,0 +1,91 @@ +askText(); + $result = $input->ask(); + + $menu->redraw(); + }; + + return $callable; + } + + /** + * + * + */ + private function addCreateItem() + { + $menu = function(CliMenuBuilder $builder) + { + $data = []; + + $builder + ->setTitle('Settings > Add') + ->disableDefaultItems() + + // input name + ->addItem('name', $this->addInputItem()) + + // input url + ->addItem('url', $this->addInputItem()) + ->addItem('handler', $this->addInputItem()) + + ->addLineBreak('-') + ->addSubMenu('actions', $this->addActions()) + + ->addLineBreak('-'); + }; + + return $menu; + } + + /** + * Execute the console command. + * + * @return mixed + */ + public function handle() + { + // create menu + $builder = $this->menu('Settings'); + + $builder + ->addSubMenu('Add', $this->addCreateItem()) + ->addLineBreak('-'); + + $mainmenu = $builder->build(); + $mainmenu->open(); + } +} diff --git a/app/Commands/CrawlerRunCommand.php b/app/Commands/CrawlerRunCommand.php index 6b729cc..61e8f98 100644 --- a/app/Commands/CrawlerRunCommand.php +++ b/app/Commands/CrawlerRunCommand.php @@ -35,12 +35,14 @@ class CrawlerRunCommand extends Command 'https://steadyhq.com/rss/insertmoin?auth=d37bffc9-9a84-4eed-95f6-3b6cb77c2406' ]; - $handler = new RssHandler(); - $response = $handler->get($url); + $handlerClass = $source->response_handler_class; + + $handler = new $handlerClass($source); + $response = $handler->getResponse(); // if it is a 200 if ($response->ok()) { - $handler->run($response, $actions); + $handler->run(); // if there is an error on the source } else if ($response->serverError()) { diff --git a/app/Commands/SettingsMenuCommand.php b/app/Commands/SettingsMenuCommand.php deleted file mode 100644 index b36eda2..0000000 --- a/app/Commands/SettingsMenuCommand.php +++ /dev/null @@ -1,43 +0,0 @@ -menu('Settings') - ->addSubMenu('Sources', [ - 'd', - 'e' - ]); - - $builder->addLineBreak('-'); - - $mainmenu = $builder->build(); - $mainmenu->open(); - } -} diff --git a/app/Handlers/Action/ActionHandler.php b/app/Handlers/Action/ActionHandler.php new file mode 100644 index 0000000..a3a6226 --- /dev/null +++ b/app/Handlers/Action/ActionHandler.php @@ -0,0 +1,26 @@ +data = $data; + } +} \ No newline at end of file diff --git a/app/Handlers/Action/ActionInterface.php b/app/Handlers/Action/ActionInterface.php index f2658ca..eefcc9e 100644 --- a/app/Handlers/Action/ActionInterface.php +++ b/app/Handlers/Action/ActionInterface.php @@ -1,6 +1,6 @@ id(); $table->string('action_handler_class'); - $table->enum('type', [ - 'before', 'after' - ])->nullable(); $table->integer('priority'); $table->unsignedBigInteger('source_id'); diff --git a/database/migrations/2021_05_09_073140_create_logs_table.php b/database/migrations/2021_05_09_073140_create_logs_table.php index 5e259ae..72608c6 100644 --- a/database/migrations/2021_05_09_073140_create_logs_table.php +++ b/database/migrations/2021_05_09_073140_create_logs_table.php @@ -21,11 +21,6 @@ class CreateLogsTable extends Migration 'critical', 'info', 'error' ]); - $table->unsignedBigInteger('source_id'); - $table->foreign('source_id') - ->references('id') - ->on('sources'); - $table->timestamps(); }); } diff --git a/resources/CustomHandlers/Action/FileMove.php b/resources/CustomHandlers/Action/FileMove.php new file mode 100644 index 0000000..4394ce6 --- /dev/null +++ b/resources/CustomHandlers/Action/FileMove.php @@ -0,0 +1,13 @@ +response = Http::withHeaders([ "Content-Type" => "text/xml;charset=utf-8" @@ -33,13 +33,15 @@ class Rss extends ResponseHandler * * */ - public function handle() + public function run() { $xml = new SimpleXMLElement($this->response->body()); foreach($xml->channel->item as $item) { foreach($this->actions as $action) { - $action->handle($item); + $actionClass = $action->action_handler_class; + $action = new ActionClass($item); + $action->run(); } } }