add undelete command
authorChristian Weiske <cweiske@cweiske.de>
Wed, 14 Sep 2016 19:31:08 +0000 (21:31 +0200)
committerChristian Weiske <cweiske@cweiske.de>
Wed, 14 Sep 2016 19:31:08 +0000 (21:31 +0200)
src/shpub/Cli.php
src/shpub/Command/Undelete.php [new file with mode: 0644]

index 75497eb46c4d19373b8b7eb60498cda5b3515482..aa9dcaa0236a31a938b4d0baef34e493fadfadf8 100644 (file)
@@ -167,6 +167,7 @@ class Cli
         Command_Repost::opts($optParser);
 
         Command_Delete::opts($optParser);
+        Command_Undelete::opts($optParser);
 
         return $optParser;
     }
diff --git a/src/shpub/Command/Undelete.php b/src/shpub/Command/Undelete.php
new file mode 100644 (file)
index 0000000..ad3525f
--- /dev/null
@@ -0,0 +1,33 @@
+<?php
+namespace shpub;
+
+class Command_Undelete extends Command_AbstractProps
+{
+    public static function opts(\Console_CommandLine $optParser)
+    {
+        $cmd = $optParser->addCommand('undelete');
+        $cmd->addArgument(
+            'url',
+            [
+                'optional'    => false,
+                'description' => 'URL to restore',
+            ]
+        );
+    }
+
+    public function run(\Console_CommandLine_Result $cmdRes)
+    {
+        $url = Validator::url($cmdRes->args['url'], 'url');
+        if ($url === false) {
+            exit(10);
+        }
+
+        $req = new Request($this->cfg->host, $this->cfg);
+        $req->req->addPostParameter('action', 'undelete');
+        $req->req->addPostParameter('url', $url);
+
+        $res = $req->send();
+        Log::info('Post restored at server');
+    }
+}
+?>