Add upload command
[shpub.git] / src / shpub / Command / AbstractProps.php
index b581f3c33e64378e8eeb9b5483c0e1122f08c3af..d939aa75f1715818c69b563d787e8795749c1faa 100644 (file)
@@ -40,6 +40,15 @@ class Command_AbstractProps
                 'default'     => [],
             )
         );
+        $cmd->addOption(
+            'direct_upload',
+            array(
+                'long_name'   => '--direct-upload',
+                'description' => 'Ignore media endpoint at file upload',
+                'action'      => 'StoreTrue',
+                'default'     => false,
+            )
+        );
         $cmd->addOption(
             'name',
             array(
@@ -170,6 +179,7 @@ class Command_AbstractProps
             );
         }
 
+        $req->setDirectUpload($cmdRes->options['direct_upload']);
         $this->handleFiles($cmdRes, $req);
 
         if (count($cmdRes->options['x'])) {
@@ -232,24 +242,15 @@ class Command_AbstractProps
             if ($type == 'image') {
                 $type = 'photo';
             }
-            if (count($urls) == 1) {
-                $req->req->addPostParameter($type, reset($urls));
-            } else if (count($urls) > 1) {
-                $n = 0;
-                foreach ($urls as $url) {
-                    $req->req->addPostParameter(
-                        $type . '[' . $n++ . ']', $url
-                    );
-                }
+            if (count($urls) > 0) {
+                $req->addProperty($type, $urls);
             }
         }
         foreach ($fileList as $type => $filePaths) {
             if ($type == 'image') {
                 $type = 'photo';
             }
-            if (count($filePaths) == 1) {
-                $req->addUpload($type, reset($filePaths));
-            } else if (count($filePaths) > 0) {
+            if (count($filePaths) > 0) {
                 $req->addUpload($type, $filePaths);
             }
         }