Passed
Push — master ( 6896fd...530886 )
by Josh
02:31
created

BlendableLoader::blendManyTemplates()   B

Complexity

Conditions 7
Paths 11

Size

Total Lines 22
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 13
dl 0
loc 22
rs 8.8333
c 0
b 0
f 0
cc 7
nc 11
nop 3
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: joshgulledge
5
 * Date: 10/1/18
6
 * Time: 12:35 PM
7
 */
8
9
namespace LCI\Blend\Helpers;
10
11
use LCI\Blend\Blender;
12
use LCI\Blend\Blendable\Context;
13
use LCI\Blend\Blendable\Chunk;
14
use LCI\Blend\Blendable\MediaSource;
15
use LCI\Blend\Blendable\Plugin;
16
use LCI\Blend\Blendable\Resource;
17
use LCI\Blend\Blendable\Snippet;
18
use LCI\Blend\Blendable\SystemSetting;
19
use LCI\Blend\Blendable\Template;
20
use LCI\Blend\Blendable\TemplateVariable;
21
use LCI\MODX\Console\Helpers\UserInteractionHandler;
22
23
class BlendableLoader
24
{
25
    // Simple class to help init blendable objects and blend/revert many
26
27
    /** @var \modX */
0 ignored issues
show
Bug introduced by
The type modX was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
28
    protected $modx;
29
30
    /** @var Blender */
31
    protected $blender;
32
33
    /** @var \LCI\MODX\Console\Helpers\UserInteractionHandler */
34
    protected $userInteractionHandler;
35
36
    /**
37
     * BlendableLoader constructor.
38
     * @param \modX $modx
39
     * @param Blender $blender
40
     * @param \LCI\MODX\Console\Helpers\UserInteractionHandler $userInteractionHandler
41
     */
42
    public function __construct(Blender $blender, \modX $modx, UserInteractionHandler $userInteractionHandler)
43
    {
44
        $this->modx = $modx;
45
        $this->blender = $blender;
46
        $this->userInteractionHandler = $userInteractionHandler;
47
    }
48
49
    /** @TODO
50
     *
51
     * 1. Move SeedMaker into Migrations
52
     * 2. Extract runMigrations to Migrator and blender just extends
53
     * 3. Add package to log DB
54
     * 4. Redo install/update
55
     * 5. History directory
56
     *
57
     * ?? LCI\Console -> LCI\ExtendableConsole - to allow xPDO to use it and then LCI\Console just has MODX specifics
58
     *
59
     *
60
     */
61
62
63
    /**
64
     * Use this method with your IDE to help manually build a Chunk with PHP
65
     * @param string $name
66
     * @return Chunk
67
     */
68
    public function getBlendableChunk($name)
69
    {
70
        /** @var \LCI\Blend\Blendable\Chunk $chunk */
71
        $chunk = new Chunk($this->modx, $this->blender, $name);
72
        return $chunk->setSeedsDir($this->blender->getSeedsDir());
73
    }
74
    /**
75
     * @param array $chunks
76
     * @param string $seeds_dir
77
     */
78
    public function blendManyChunks($chunks = [], $seeds_dir = '')
79
    {
80
        // will update if element does exist or create new
81
        foreach ($chunks as $seed_key) {
82
            /** @var \LCI\Blend\Blendable\Chunk $blendChunk */
83
            $blendChunk = new Chunk($this->modx, $this->blender, $this->blender->getNameFromSeedKey($seed_key));
84
            if (!empty($seeds_dir)) {
85
                $blendChunk->setSeedsDir($seeds_dir);
86
            }
87
            if ($blendChunk->blendFromSeed($seed_key)) {
88
                $this->blender->out($seed_key.' has been blended into ID: ');
89
90
            } elseif ($blendChunk->isExists()) {
91
                $this->blender->out($seed_key.' chunk already exists', true);
92
                if ($this->userInteractionHandler->promptConfirm('Would you like to update?', true)) {
93
                    if ($blendChunk->blendFromSeed($seed_key, true)) {
94
                        $this->blender->out($seed_key.' has been blended');
95
                    }
96
                }
97
            } else {
98
                $this->blender->out('There was an error saving '.$seed_key, true);
99
            }
100
        }
101
    }
102
103
    /**
104
     * @param array $chunks
105
     * @param string $seeds_dir
106
     */
107
    public function revertBlendManyChunks($chunks = [], $seeds_dir = '')
108
    {
109
        // will update if system setting does exist or create new
110
        foreach ($chunks as $seed_key) {
111
            /** @var \LCI\Blend\Blendable\Chunk $blendChunk */
112
            $blendChunk = new Chunk($this->modx, $this->blender, $this->blender->getNameFromSeedKey($seed_key));
113
            if (!empty($seeds_dir)) {
114
                $blendChunk->setSeedsDir($seeds_dir);
115
            }
116
117
            if ($blendChunk->revertBlend()) {
118
                $this->blender->out($blendChunk->getFieldName().' chunk has been reverted to '.$seeds_dir);
119
120
            } else {
121
                $this->blender->out($blendChunk->getFieldName().' chunk was not reverted', true);
122
            }
123
        }
124
    }
125
126
    /**
127
     * Use this method with your IDE to help manually build a Chunk with PHP
128
     * @param string $key
129
     * @return Context
130
     */
131
    public function getBlendableContext($key)
132
    {
133
        /** @var \LCI\Blend\Blendable\Context $chunk */
134
        $context = new Context($this->modx, $this->blender, $key);
135
        return $context->setSeedsDir($this->blender->getSeedsDir());
136
    }
137
138
    /**
139
     * @param array $contexts
140
     * @param string $seeds_dir
141
     */
142
    public function blendManyContexts($contexts = [], $seeds_dir = '')
143
    {
144
        // will update if element does exist or create new
145
        foreach ($contexts as $seed_key) {
146
            /** @var \LCI\Blend\Blendable\Context $blendContext */
147
            $blendContext = new Context($this->modx, $this->blender, $this->blender->getNameFromSeedKey($seed_key));
148
            if (!empty($seeds_dir)) {
149
                $blendContext->setSeedsDir($seeds_dir);
150
            }
151
            if ($blendContext->blendFromSeed($seed_key)) {
152
                $this->blender->out($seed_key.' has been blended ');
153
154
            } elseif ($blendContext->isExists()) {
155
                $this->blender->out($seed_key.' context already exists', true);
156
                if ($this->userInteractionHandler->promptConfirm('Would you like to update?', true)) {
157
                    if ($blendContext->blendFromSeed($seed_key, true)) {
158
                        $this->blender->out($seed_key.' has been blended');
159
                    }
160
                }
161
            } else {
162
                $this->blender->out('There was an error saving '.$seed_key, true);
163
            }
164
        }
165
    }
166
167
    /**
168
     * @param array $contexts
169
     * @param string $seeds_dir
170
     */
171
    public function revertBlendManyContexts($contexts = [], $seeds_dir = '')
172
    {
173
        // will update if system setting does exist or create new
174
        foreach ($contexts as $seed_key) {
175
            /** @var \LCI\Blend\Blendable\Context $blendContext */
176
            $blendContext = new Context($this->modx, $this->blender, $this->blender->getNameFromSeedKey($seed_key));
177
            if (!empty($seeds_dir)) {
178
                $blendContext->setSeedsDir($seeds_dir);
179
            }
180
181
            if ($blendContext->revertBlend()) {
182
                $this->blender->out($blendContext->getFieldKey().' context has been reverted to '.$seeds_dir);
183
184
            } else {
185
                $this->blender->out($blendContext->getFieldKey().' context was not reverted', true);
186
            }
187
        }
188
    }
189
190
191
    /**
192
     * @param string $name
193
     * @return \LCI\Blend\Blendable\MediaSource
194
     */
195
    public function getBlendableMediaSource($name)
196
    {
197
        /** @var \LCI\Blend\Blendable\MediaSource $mediaSource */
198
        $mediaSource = new MediaSource($this->modx, $this->blender, $name);
199
        return $mediaSource
200
            ->setFieldName($name)
201
            ->setSeedsDir($this->blender->getSeedsDir());
202
    }
203
204
    /**
205
     * @param array $media_sources
206
     * @param string $seeds_dir
207
     */
208
    public function blendManyMediaSources($media_sources = [], $seeds_dir = '')
209
    {
210
        // will update if element does exist or create new
211
        foreach ($media_sources as $seed_key) {
212
            /** @var \LCI\Blend\Blendable\MediaSource $blendMediaSource */
213
            $blendMediaSource = new MediaSource($this->modx, $this->blender);
214
            if (!empty($seeds_dir)) {
215
                $blendMediaSource->setSeedsDir($seeds_dir);
216
            }
217
            if ($blendMediaSource->blendFromSeed($seed_key)) {
218
                $this->blender->out($seed_key.' has been blended into ID: ');
219
220
            } elseif ($blendMediaSource->isExists()) {
221
                $this->blender->out($seed_key.' media source already exists', true);
222
                if ($this->userInteractionHandler->promptConfirm('Would you like to update?', true)) {
223
                    if ($blendMediaSource->blendFromSeed($seed_key, true)) {
224
                        $this->blender->out($seed_key.' has been blended');
225
                    }
226
                }
227
            } else {
228
                $this->blender->out('There was an error saving '.$seed_key, true);
229
            }
230
        }
231
    }
232
233
    /**
234
     * @param array $media_sources
235
     * @param string $seeds_dir
236
     */
237
    public function revertBlendManyMediaSources($media_sources = [], $seeds_dir = '')
238
    {
239
        // will update if system setting does exist or create new
240
        foreach ($media_sources as $seed_key) {
241
            /** @var \LCI\Blend\Blendable\MediaSource $blendMediaSource */
242
            $blendMediaSource = new MediaSource($this->modx, $this->blender, $this->blender->getNameFromSeedKey($seed_key));
243
            if (!empty($seeds_dir)) {
244
                $blendMediaSource->setSeedsDir($seeds_dir);
245
            }
246
247
            if ($blendMediaSource->revertBlend()) {
248
                $this->blender->out($blendMediaSource->getFieldName().' media source has been reverted to '.$seeds_dir);
249
250
            } else {
251
                $this->blender->out($blendMediaSource->getFieldName().' media source was not reverted', true);
252
            }
253
        }
254
    }
255
256
    /**
257
     * Use this method with your IDE to help manually build a Plugin with PHP
258
     * @param string $name
259
     * @return \LCI\Blend\Blendable\Plugin
260
     */
261
    public function getBlendablePlugin($name)
262
    {
263
        /** @var \LCI\Blend\Blendable\Plugin $plugin */
264
        $plugin = new Plugin($this->modx, $this->blender, $name);
265
        return $plugin->setSeedsDir($this->blender->getSeedsDir());
266
    }
267
268
    /**
269
     * @param array $plugins
270
     * @param string $seeds_dir
271
     */
272
    public function blendManyPlugins($plugins = [], $seeds_dir = '')
273
    {
274
        // will update if element does exist or create new
275
        foreach ($plugins as $seed_key) {
276
            /** @var \LCI\Blend\Blendable\Plugin $blendPlugin */
277
            $blendPlugin = new Plugin($this->modx, $this->blender, $this->blender->getNameFromSeedKey($seed_key));
278
            if (!empty($seeds_dir)) {
279
                $blendPlugin->setSeedsDir($seeds_dir);
280
            }
281
            if ($blendPlugin->blendFromSeed($seed_key)) {
282
                $this->blender->out($seed_key.' has been blended into ID: ');
283
284
            } elseif ($blendPlugin->isExists()) {
285
                $this->blender->out($seed_key.' plugin already exists', true);
286
                if ($this->userInteractionHandler->promptConfirm('Would you like to update?', true)) {
287
                    if ($blendPlugin->blendFromSeed($seed_key, true)) {
288
                        $this->blender->out($seed_key.' has been blended');
289
                    }
290
                }
291
            } else {
292
                $this->blender->out('There was an error saving '.$seed_key, true);
293
            }
294
        }
295
    }
296
297
    /**
298
     * @param array $plugins
299
     * @param string $seeds_dir
300
     */
301
    public function revertBlendManyPlugins($plugins = [], $seeds_dir = '')
302
    {
303
        // will update if system setting does exist or create new
304
        foreach ($plugins as $seed_key) {
305
            /** @var \LCI\Blend\Blendable\Plugin $blendPlugin */
306
            $blendPlugin = new Plugin($this->modx, $this->blender, $this->blender->getNameFromSeedKey($seed_key));
307
            if (!empty($seeds_dir)) {
308
                $blendPlugin->setSeedsDir($seeds_dir);
309
            }
310
311
            if ($blendPlugin->revertBlend()) {
312
                $this->blender->out($blendPlugin->getFieldName().' plugin has been reverted to '.$seeds_dir);
313
314
            } else {
315
                $this->blender->out($blendPlugin->getFieldName().' plugin was not reverted', true);
316
            }
317
        }
318
    }
319
320
    /**
321
     * Use this method with your IDE to help manually build a Snippet with PHP
322
     * @param string $name
323
     * @return \LCI\Blend\Blendable\Snippet
324
     */
325
    public function getBlendableSnippet($name)
326
    {
327
        /** @var Snippet $snippet */
328
        $snippet = new Snippet($this->modx, $this->blender, $name);
329
        return $snippet->setSeedsDir($this->blender->getSeedsDir());
330
    }
331
332
    /**
333
     * @param array $snippets
334
     * @param string $seeds_dir
335
     */
336
    public function blendManySnippets($snippets = [], $seeds_dir = '')
337
    {
338
        // will update if element does exist or create new
339
        foreach ($snippets as $seed_key) {
340
            /** @var \LCI\Blend\Blendable\Snippet $blendSnippet */
341
            $blendSnippet = new Snippet($this->modx, $this->blender, $this->blender->getNameFromSeedKey($seed_key));
342
            if (!empty($seeds_dir)) {
343
                $blendSnippet->setSeedsDir($seeds_dir);
344
            }
345
            if ($blendSnippet->blendFromSeed($seed_key)) {
346
                $this->blender->out($seed_key.' has been blended');
347
348
            } elseif ($blendSnippet->isExists()) {
349
                $this->blender->out($seed_key.' snippet already exists', true);
350
                if ($this->userInteractionHandler->promptConfirm('Would you like to update?', true)) {
351
                    if ($blendSnippet->blendFromSeed($seed_key, true)) {
352
                        $this->blender->out($seed_key.' has been blended');
353
                    }
354
                }
355
            } else {
356
                $this->blender->out('There was an error saving '.$seed_key, true);
357
            }
358
        }
359
    }
360
    /**
361
     * @param array $snippets
362
     * @param string $seeds_dir
363
     */
364
    public function revertBlendManySnippets($snippets = [], $seeds_dir = '')
365
    {
366
        // will update if system setting does exist or create new
367
        foreach ($snippets as $seed_key) {
368
            /** @var Snippet $blendSnippet */
369
            $blendSnippet = new Snippet($this->modx, $this->blender, $this->blender->getNameFromSeedKey($seed_key));
370
            if (!empty($seeds_dir)) {
371
                $blendSnippet->setSeedsDir($seeds_dir);
372
            }
373
374
            if ($blendSnippet->revertBlend()) {
375
                $this->blender->out($blendSnippet->getFieldName().' snippet has been reverted to '.$seeds_dir);
376
377
            } else {
378
                $this->blender->out($blendSnippet->getFieldName().' snippet was not reverted', true);
379
            }
380
        }
381
    }
382
383
    /**
384
     * Use this method with your IDE to manually build a template
385
     * @param string $name
386
     * @return \LCI\Blend\Blendable\Template
387
     */
388
    public function getBlendableTemplate($name)
389
    {
390
        /** @var \LCI\Blend\Blendable\Template $template */
391
        $template = new Template($this->modx, $this->blender, $name);
392
        return $template->setSeedsDir($this->blender->getSeedsDir());
393
    }
394
395
    /**
396
     * @param array $templates
397
     * @param string $seeds_dir
398
     * @param bool $overwrite
399
     */
400
    public function blendManyTemplates($templates = [], $seeds_dir = '', $overwrite = false)
401
    {
402
        // will update if template does exist or create new
403
        foreach ($templates as $seed_key) {
404
405
            /** @var \LCI\Blend\Blendable\Template $blendTemplate */
406
            $blendTemplate = new Template($this->modx, $this->blender, $this->blender->getNameFromSeedKey($seed_key));
407
            if (!empty($seeds_dir)) {
408
                $blendTemplate->setSeedsDir($seeds_dir);
409
            }
410
            if ($blendTemplate->blendFromSeed($seed_key, $overwrite)) {
411
                $this->blender->out($seed_key.' has been blended');
412
413
            } elseif ($blendTemplate->isExists()) {
414
                $this->blender->out($seed_key.' template already exists', true);
415
                if ($this->userInteractionHandler->promptConfirm('Would you like to update?', true)) {
416
                    if ($blendTemplate->blendFromSeed($seed_key, true)) {
417
                        $this->blender->out($seed_key.' has been blended');
418
                    }
419
                }
420
            } else {
421
                $this->blender->out('There was an error saving '.$seed_key, true);
422
            }
423
        }
424
    }
425
426
    /**
427
     * @param array $templates
428
     * @param string $seeds_dir
429
     */
430
    public function revertBlendManyTemplates($templates = [], $seeds_dir = '')
431
    {
432
        // will update if system setting does exist or create new
433
        foreach ($templates as $seed_key) {
434
            /** @var \LCI\Blend\Blendable\Template $blendTemplate */
435
            $blendTemplate = new Template($this->modx, $this->blender, $this->blender->getNameFromSeedKey($seed_key));
436
            if (!empty($seeds_dir)) {
437
                $blendTemplate->setSeedsDir($seeds_dir);
438
            }
439
440
            if ($blendTemplate->revertBlend()) {
441
                $this->blender->out($blendTemplate->getFieldName().' template has been reverted to '.$seeds_dir);
442
443
            } else {
444
                $this->blender->out($blendTemplate->getFieldName().' template was not reverted', true);
445
            }
446
        }
447
    }
448
449
    /**
450
     * Use this method with your IDE to manually build a template variable
451
     * @param string $name
452
     * @return TemplateVariable
453
     */
454
    public function getBlendableTemplateVariable($name)
455
    {
456
        /** @var \LCI\Blend\Blendable\TemplateVariable $tv */
457
        $tv = new TemplateVariable($this->modx, $this->blender, $name);
458
        return $tv->setSeedsDir($this->blender->getSeedsDir());
459
    }
460
461
    /**
462
     * @param string $alias
463
     * @param  string $context
464
     * @return \LCI\Blend\Blendable\Resource
465
     */
466
    public function getBlendableResource($alias, $context = 'web')
467
    {
468
        /** @var \LCI\Blend\Blendable\Resource $resource */
469
        $resource = new Resource($this->modx, $this->blender, $alias, $context);
470
        return $resource
471
            ->setSeedsDir($this->blender->getSeedsDir());
472
    }
473
    /**
474
     * @param array $resources
475
     * @param string $seeds_dir
476
     * @param bool $overwrite
477
     *
478
     * @return bool
479
     */
480
    public function blendManyResources($resources = [], $seeds_dir = '', $overwrite = false)
481
    {
482
        $saved = true;
483
        // will update if resource does exist or create new
484
        foreach ($resources as $context => $seeds) {
485
            foreach ($seeds as $seed_key) {
486
                /** @var \LCI\Blend\Blendable\Resource $blendResource */
487
                $blendResource = new Resource($this->modx, $this->blender, $this->blender->getAliasFromSeedKey($seed_key), $context);
488
489
                if (!empty($seeds_dir)) {
490
                    $blendResource->setSeedsDir($seeds_dir);
491
                }
492
493
                if ($blendResource->blendFromSeed($seed_key, $overwrite)) {
494
                    $this->blender->out($seed_key.' has been blended into ID: ');
495
496
                } elseif ($blendResource->isExists()) {
497
                    $this->blender->out($seed_key.' already exists', true);
498
                    if ($this->userInteractionHandler->promptConfirm('Would you like to update?', true)) {
499
                        if ($blendResource->blendFromSeed($seed_key, true)) {
500
                            $this->blender->out($seed_key.' has been blended into ID: ');
501
                        }
502
                    }
503
                } else {
504
                    $this->blender->out('There was an error saving '.$seed_key, true);
505
                    echo 'There was an error saving '.$seed_key; exit();
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
506
                    $saved = false;
0 ignored issues
show
Unused Code introduced by
$saved = false is not reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
507
                }
508
            }
509
        }
510
511
        return $saved;
512
    }
513
514
    /**
515
     * @param array $resources
516
     * @param string $seeds_dir
517
     * @param bool $overwrite
518
     *
519
     * @return bool
520
     */
521
    public function revertBlendManyResources($resources = [], $seeds_dir = '', $overwrite = false)
0 ignored issues
show
Unused Code introduced by
The parameter $overwrite is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

521
    public function revertBlendManyResources($resources = [], $seeds_dir = '', /** @scrutinizer ignore-unused */ $overwrite = false)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
522
    {
523
        $saved = true;
524
        // will update if resource does exist or create new
525
        foreach ($resources as $context => $seeds) {
526
            foreach ($seeds as $seed_key) {
527
                /** @var \LCI\Blend\Blendable\Resource $blendResource */
528
                $blendResource = new Resource($this->modx, $this->blender, $this->blender->getAliasFromSeedKey($seed_key), $context);
529
530
                if (!empty($seeds_dir)) {
531
                    $blendResource->setSeedsDir($seeds_dir);
532
                }
533
                if ($blendResource->revertBlend()) {
534
                    $this->blender->out($seed_key.' has been reverted ');
535
536
                } else {
537
                    $this->blender->out('There was an error reverting resource '.$seed_key, true);
538
                    $saved = false;
539
                }
540
            }
541
        }
542
543
        return $saved;
544
    }
545
546
    /**
547
     * @param string $key
548
     * @return \LCI\Blend\Blendable\SystemSetting
549
     */
550
    public function getBlendableSystemSetting($key = '')
551
    {
552
        /** @var \LCI\Blend\Blendable\SystemSetting $systemSetting */
553
        $systemSetting = new SystemSetting($this->modx, $this->blender, $key);
554
        return $systemSetting->setSeedsDir($this->blender->getSeedsDir());
555
    }
556
557
    /**
558
     * @param array $settings ~ [ ['name' => 'mySystemSetting', 'value' => 'myValue'], ..]
559
     * @param string $seeds_dir
560
     *
561
     * @return bool
562
     */
563
    public function blendManySystemSettings($settings = [], $seeds_dir = '')
564
    {
565
        $success = true;
566
        // will update if system setting does exist or create new
567
        foreach ($settings as $data) {
568
            if (isset($data['columns'])) {
569
                $setting = $data['columns'];
570
            } else {
571
                $setting = $data;
572
                $data['columns'] = $data;
573
            }
574
575
            if (isset($setting['key'])) {
576
                $key = $setting['key'];
577
578
            } elseif (isset($setting['name'])) {
579
                $key = $setting['name'];
580
581
            } else {
582
                // Error: no name/key
583
                $success = false;
584
                continue;
585
            }
586
587
            $systemSetting = $this->getBlendableSystemSetting($key);
588
            if (!empty($seeds_dir)) {
589
                $systemSetting->setSeedsDir($seeds_dir);
590
            }
591
592
            if ($systemSetting->blendFromArray($data, true)) {
593
                $this->blender->out($systemSetting->getFieldName().' setting has been blended');
594
            } else {
595
                $success = false;
596
            }
597
        }
598
599
        return $success;
600
    }
601
602
    /**
603
     * @param array $settings ~ [ ['name' => 'mySystemSetting', 'value' => 'myValue'], ..]
604
     * @param string $seeds_dir
605
     *
606
     * @return bool
607
     */
608
    public function revertBlendManySystemSettings($settings = [], $seeds_dir = '')
609
    {
610
        $success = true;
611
        // will update if system setting does exist or create new
612
        foreach ($settings as $data) {
613
            if (isset($data['columns'])) {
614
                $setting = $data['columns'];
615
            } else {
616
                $setting = $data;
617
                $data['columns'] = $data;
618
            }
619
620
            if (isset($setting['key'])) {
621
                $key = $setting['key'];
622
623
            } elseif (isset($setting['name'])) {
624
                $key = $setting['name'];
625
626
            } else {
627
                // Error: no name/key
628
                $success = false;
629
                continue;
630
            }
631
632
            $systemSetting = $this->getBlendableSystemSetting($key);
633
634
            if (!empty($seeds_dir)) {
635
                $systemSetting->setSeedsDir($seeds_dir);
636
            }
637
638
            if ($systemSetting->revertBlend()) {
639
                $this->blender->out($systemSetting->getFieldName().' setting has been reverted to '.$seeds_dir);
640
641
            } else {
642
                $this->blender->out($systemSetting->getFieldName().' setting was not reverted', true);
643
                $success = false;
644
            }
645
        }
646
647
        return $success;
648
    }
649
650
}