ReviewOS

also looking at this

meemalabs/meema-client-php

Bulk folders

#31
Merged glennmichael123 wants to merge bulk-folders into main
3 files +80 -14

Review threads live on the whole diff, not on one commit, so none are shown here - a thread's line means something in the branch's final form, and painting it into an intermediate step would put it on code it is not about.

src/Models/Folder.phpmodified+55-10
Changes to src/Models/Folder.php
@@ -137,15 +137,27 @@ class Folder
137137 */
138138 public function delete($id)
139139 {
140 if (! is_int($id)) {
141 throw new InvalidFormatException();
140 $ids = is_array($id) ? $id : func_get_args();
141
142 foreach ($ids as $id) {
143 if (! is_int($id)) {
144 throw new InvalidFormatException();
145 }
146
147 if ($this->model) {
148 return $this->deleteFolderFromMedia($this->model->getId(), $id);
149 }
142150 }
143151
144 if ($this->model) {
145 return $this->deleteFolderFromMedia($this->model->getId(), $id);
152 if (count($ids) > 1) {
153 return $this->client->request('POST', 'bulk/folders/delete', ['folder_ids' => $ids]);
146154 }
147155
156 // If count is equal to 1 get the first element
157 $id = $ids[0];
158
148159 return $this->client->request('DELETE', "folders/{$id}");
160
149161 }
150162
151163 /**
@@ -171,10 +183,21 @@ class Folder
171183 */
172184 public function archive($id)
173185 {
174 if (! is_int($id)) {
175 throw new InvalidFormatException();
186 $ids = is_array($id) ? $id : func_get_args();
187
188 foreach ($ids as $id) {
189 if (! is_int($id)) {
190 throw new InvalidFormatException();
191 }
176192 }
177193
194 if (count($ids) > 1) {
195 return $this->client->request('POST', 'bulk/folders/archive', ['folder_ids' => $ids]);
196 }
197
198 // If count is equal to 1 get the first element
199 $id = $ids[0];
200
178201 return $this->client->request('POST', "folders/{$id}/archive");
179202 }
180203
@@ -189,10 +212,21 @@ class Folder
189212 */
190213 public function unarchive($id)
191214 {
192 if (! is_int($id)) {
193 throw new InvalidFormatException();
215 $ids = is_array($id) ? $id : func_get_args();
216
217 foreach ($ids as $id) {
218 if (! is_int($id)) {
219 throw new InvalidFormatException();
220 }
194221 }
195222
223 if (count($ids) > 1) {
224 return $this->client->request('POST', 'bulk/folders/unarchive', ['folder_ids' => $ids]);
225 }
226
227 // If count is equal to 1 get the first element
228 $id = $ids[0];
229
196230 return $this->client->request('POST', "folders/{$id}/unarchive");
197231 }
198232
@@ -207,10 +241,21 @@ class Folder
207241 */
208242 public function duplicate($id): array
209243 {
210 if (! is_int($id)) {
211 throw new InvalidFormatException();
244 $ids = is_array($id) ? $id : func_get_args();
245
246 foreach ($ids as $id) {
247 if (! is_int($id)) {
248 throw new InvalidFormatException();
249 }
212250 }
213251
252 if (count($ids) > 1) {
253 return $this->client->request('POST', 'bulk/folders/duplicate', ['folder_ids' => $ids]);
254 }
255
256 // If count is equal to 1 get the first element
257 $id = $ids[0];
258
214259 return $this->client->request('POST', "folders/{$id}/duplicate");
215260 }
216261