Release 0.7.1
[shpub.git] / src / shpub / Command / Undelete.php
1 <?php
2 namespace shpub;
3
4 class Command_Undelete extends Command_AbstractProps
5 {
6     public static function opts(\Console_CommandLine $optParser)
7     {
8         $cmd = $optParser->addCommand('undelete');
9         $cmd->description = 'Restore a deleted post';
10         static::addOptJson($cmd);
11         $cmd->addArgument(
12             'url',
13             [
14                 'optional'    => false,
15                 'description' => 'URL to restore',
16             ]
17         );
18     }
19
20     public function run(\Console_CommandLine_Result $cmdRes)
21     {
22         $url = Validator::url($cmdRes->args['url'], 'url');
23         if ($url === false) {
24             exit(10);
25         }
26
27         $req = new Request($this->cfg->host, $this->cfg);
28         $this->handleOptJson($cmdRes, $req);
29         $req->setAction('undelete');
30         $req->setUrl($url);
31
32         $res = $req->send();
33         Log::info('Post restored at server');
34     }
35 }
36 ?>