55dd6b99ccf51c36f9b87433d36c904da0d51493
[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         static::addOptJson($cmd);
10         $cmd->addArgument(
11             'url',
12             [
13                 'optional'    => false,
14                 'description' => 'URL to restore',
15             ]
16         );
17     }
18
19     public function run(\Console_CommandLine_Result $cmdRes)
20     {
21         $url = Validator::url($cmdRes->args['url'], 'url');
22         if ($url === false) {
23             exit(10);
24         }
25
26         $req = new Request($this->cfg->host, $this->cfg);
27         $this->handleOptJson($cmdRes, $req);
28         $req->setAction('undelete');
29         $req->setUrl($url);
30
31         $res = $req->send();
32         Log::info('Post restored at server');
33     }
34 }
35 ?>