-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscript.php
711 lines (656 loc) · 37.5 KB
/
script.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
<?php
/*----------------------------------------------------------------------------------| www.vdm.io |----/
Vast Development Method
/-------------------------------------------------------------------------------------------------------/
@version 1.0.2
@build 14th December, 2020
@created 5th July, 2020
@package Recipe Manager
@subpackage script.php
@author Oh Martin <https://www.vdm.io>
@copyright Copyright (C) 2020. All Rights Reserved
@license GNU General Public License version 2 or later; see LICENSE.txt
____ _____ _____ __ __ __ __ ___ _____ __ __ ____ _____ _ _ ____ _ _ ____
(_ _)( _ )( _ )( \/ )( ) /__\ / __)( _ )( \/ )( _ \( _ )( \( )( ___)( \( )(_ _)
.-_)( )(_)( )(_)( ) ( )(__ /(__)\ ( (__ )(_)( ) ( )___/ )(_)( ) ( )__) ) ( )(
\____) (_____)(_____)(_/\/\_)(____)(__)(__) \___)(_____)(_/\/\_)(__) (_____)(_)\_)(____)(_)\_) (__)
/------------------------------------------------------------------------------------------------------*/
// No direct access to this file
defined('_JEXEC') or die('Restricted access');
JHTML::_('behavior.modal');
/**
* Script File of Recipe_manager Component
*/
class com_recipe_managerInstallerScript
{
/**
* Constructor
*
* @param JAdapterInstance $parent The object responsible for running this script
*/
public function __construct(JAdapterInstance $parent) {}
/**
* Called on installation
*
* @param JAdapterInstance $parent The object responsible for running this script
*
* @return boolean True on success
*/
public function install(JAdapterInstance $parent) {}
/**
* Called on uninstallation
*
* @param JAdapterInstance $parent The object responsible for running this script
*/
public function uninstall(JAdapterInstance $parent)
{
// [Interpretation 8043] Get Application object
$app = JFactory::getApplication();
// [Interpretation 8048] Get The Database object
$db = JFactory::getDbo();
// [Interpretation 8255] Create a new query object.
$query = $db->getQuery(true);
// [Interpretation 8259] Select id from content type table
$query->select($db->quoteName('type_id'));
$query->from($db->quoteName('#__content_types'));
// [Interpretation 8266] Where Ingredient alias is found
$query->where( $db->quoteName('type_alias') . ' = '. $db->quote('com_recipe_manager.ingredient') );
$db->setQuery($query);
// [Interpretation 8273] Execute query to see if alias is found
$db->execute();
$ingredient_found = $db->getNumRows();
// [Interpretation 8279] Now check if there were any rows
if ($ingredient_found)
{
// [Interpretation 8285] Since there are load the needed ingredient type ids
$ingredient_ids = $db->loadColumn();
// [Interpretation 8293] Remove Ingredient from the content type table
$ingredient_condition = array( $db->quoteName('type_alias') . ' = '. $db->quote('com_recipe_manager.ingredient') );
// [Interpretation 8300] Create a new query object.
$query = $db->getQuery(true);
$query->delete($db->quoteName('#__content_types'));
$query->where($ingredient_condition);
$db->setQuery($query);
// [Interpretation 8310] Execute the query to remove Ingredient items
$ingredient_done = $db->execute();
if ($ingredient_done)
{
// [Interpretation 8318] If successfully remove Ingredient add queued success message.
$app->enqueueMessage(JText::_('The (com_recipe_manager.ingredient) type alias was removed from the <b>#__content_type</b> table'));
}
// [Interpretation 8329] Remove Ingredient items from the contentitem tag map table
$ingredient_condition = array( $db->quoteName('type_alias') . ' = '. $db->quote('com_recipe_manager.ingredient') );
// [Interpretation 8335] Create a new query object.
$query = $db->getQuery(true);
$query->delete($db->quoteName('#__contentitem_tag_map'));
$query->where($ingredient_condition);
$db->setQuery($query);
// [Interpretation 8345] Execute the query to remove Ingredient items
$ingredient_done = $db->execute();
if ($ingredient_done)
{
// [Interpretation 8353] If successfully remove Ingredient add queued success message.
$app->enqueueMessage(JText::_('The (com_recipe_manager.ingredient) type alias was removed from the <b>#__contentitem_tag_map</b> table'));
}
// [Interpretation 8364] Remove Ingredient items from the ucm content table
$ingredient_condition = array( $db->quoteName('core_type_alias') . ' = ' . $db->quote('com_recipe_manager.ingredient') );
// [Interpretation 8370] Create a new query object.
$query = $db->getQuery(true);
$query->delete($db->quoteName('#__ucm_content'));
$query->where($ingredient_condition);
$db->setQuery($query);
// [Interpretation 8380] Execute the query to remove Ingredient items
$ingredient_done = $db->execute();
if ($ingredient_done)
{
// [Interpretation 8388] If successfully removed Ingredient add queued success message.
$app->enqueueMessage(JText::_('The (com_recipe_manager.ingredient) type alias was removed from the <b>#__ucm_content</b> table'));
}
// [Interpretation 8399] Make sure that all the Ingredient items are cleared from DB
foreach ($ingredient_ids as $ingredient_id)
{
// [Interpretation 8407] Remove Ingredient items from the ucm base table
$ingredient_condition = array( $db->quoteName('ucm_type_id') . ' = ' . $ingredient_id);
// [Interpretation 8414] Create a new query object.
$query = $db->getQuery(true);
$query->delete($db->quoteName('#__ucm_base'));
$query->where($ingredient_condition);
$db->setQuery($query);
// [Interpretation 8424] Execute the query to remove Ingredient items
$db->execute();
// [Interpretation 8431] Remove Ingredient items from the ucm history table
$ingredient_condition = array( $db->quoteName('ucm_type_id') . ' = ' . $ingredient_id);
// [Interpretation 8437] Create a new query object.
$query = $db->getQuery(true);
$query->delete($db->quoteName('#__ucm_history'));
$query->where($ingredient_condition);
$db->setQuery($query);
// [Interpretation 8447] Execute the query to remove Ingredient items
$db->execute();
}
}
// [Interpretation 8255] Create a new query object.
$query = $db->getQuery(true);
// [Interpretation 8259] Select id from content type table
$query->select($db->quoteName('type_id'));
$query->from($db->quoteName('#__content_types'));
// [Interpretation 8266] Where Recipe alias is found
$query->where( $db->quoteName('type_alias') . ' = '. $db->quote('com_recipe_manager.recipe') );
$db->setQuery($query);
// [Interpretation 8273] Execute query to see if alias is found
$db->execute();
$recipe_found = $db->getNumRows();
// [Interpretation 8279] Now check if there were any rows
if ($recipe_found)
{
// [Interpretation 8285] Since there are load the needed recipe type ids
$recipe_ids = $db->loadColumn();
// [Interpretation 8293] Remove Recipe from the content type table
$recipe_condition = array( $db->quoteName('type_alias') . ' = '. $db->quote('com_recipe_manager.recipe') );
// [Interpretation 8300] Create a new query object.
$query = $db->getQuery(true);
$query->delete($db->quoteName('#__content_types'));
$query->where($recipe_condition);
$db->setQuery($query);
// [Interpretation 8310] Execute the query to remove Recipe items
$recipe_done = $db->execute();
if ($recipe_done)
{
// [Interpretation 8318] If successfully remove Recipe add queued success message.
$app->enqueueMessage(JText::_('The (com_recipe_manager.recipe) type alias was removed from the <b>#__content_type</b> table'));
}
// [Interpretation 8329] Remove Recipe items from the contentitem tag map table
$recipe_condition = array( $db->quoteName('type_alias') . ' = '. $db->quote('com_recipe_manager.recipe') );
// [Interpretation 8335] Create a new query object.
$query = $db->getQuery(true);
$query->delete($db->quoteName('#__contentitem_tag_map'));
$query->where($recipe_condition);
$db->setQuery($query);
// [Interpretation 8345] Execute the query to remove Recipe items
$recipe_done = $db->execute();
if ($recipe_done)
{
// [Interpretation 8353] If successfully remove Recipe add queued success message.
$app->enqueueMessage(JText::_('The (com_recipe_manager.recipe) type alias was removed from the <b>#__contentitem_tag_map</b> table'));
}
// [Interpretation 8364] Remove Recipe items from the ucm content table
$recipe_condition = array( $db->quoteName('core_type_alias') . ' = ' . $db->quote('com_recipe_manager.recipe') );
// [Interpretation 8370] Create a new query object.
$query = $db->getQuery(true);
$query->delete($db->quoteName('#__ucm_content'));
$query->where($recipe_condition);
$db->setQuery($query);
// [Interpretation 8380] Execute the query to remove Recipe items
$recipe_done = $db->execute();
if ($recipe_done)
{
// [Interpretation 8388] If successfully removed Recipe add queued success message.
$app->enqueueMessage(JText::_('The (com_recipe_manager.recipe) type alias was removed from the <b>#__ucm_content</b> table'));
}
// [Interpretation 8399] Make sure that all the Recipe items are cleared from DB
foreach ($recipe_ids as $recipe_id)
{
// [Interpretation 8407] Remove Recipe items from the ucm base table
$recipe_condition = array( $db->quoteName('ucm_type_id') . ' = ' . $recipe_id);
// [Interpretation 8414] Create a new query object.
$query = $db->getQuery(true);
$query->delete($db->quoteName('#__ucm_base'));
$query->where($recipe_condition);
$db->setQuery($query);
// [Interpretation 8424] Execute the query to remove Recipe items
$db->execute();
// [Interpretation 8431] Remove Recipe items from the ucm history table
$recipe_condition = array( $db->quoteName('ucm_type_id') . ' = ' . $recipe_id);
// [Interpretation 8437] Create a new query object.
$query = $db->getQuery(true);
$query->delete($db->quoteName('#__ucm_history'));
$query->where($recipe_condition);
$db->setQuery($query);
// [Interpretation 8447] Execute the query to remove Recipe items
$db->execute();
}
}
// [Interpretation 8255] Create a new query object.
$query = $db->getQuery(true);
// [Interpretation 8259] Select id from content type table
$query->select($db->quoteName('type_id'));
$query->from($db->quoteName('#__content_types'));
// [Interpretation 8266] Where Recipe catid alias is found
$query->where( $db->quoteName('type_alias') . ' = '. $db->quote('com_recipe_manager.recipe.category') );
$db->setQuery($query);
// [Interpretation 8273] Execute query to see if alias is found
$db->execute();
$recipe_catid_found = $db->getNumRows();
// [Interpretation 8279] Now check if there were any rows
if ($recipe_catid_found)
{
// [Interpretation 8285] Since there are load the needed recipe_catid type ids
$recipe_catid_ids = $db->loadColumn();
// [Interpretation 8293] Remove Recipe catid from the content type table
$recipe_catid_condition = array( $db->quoteName('type_alias') . ' = '. $db->quote('com_recipe_manager.recipe.category') );
// [Interpretation 8300] Create a new query object.
$query = $db->getQuery(true);
$query->delete($db->quoteName('#__content_types'));
$query->where($recipe_catid_condition);
$db->setQuery($query);
// [Interpretation 8310] Execute the query to remove Recipe catid items
$recipe_catid_done = $db->execute();
if ($recipe_catid_done)
{
// [Interpretation 8318] If successfully remove Recipe catid add queued success message.
$app->enqueueMessage(JText::_('The (com_recipe_manager.recipe.category) type alias was removed from the <b>#__content_type</b> table'));
}
// [Interpretation 8329] Remove Recipe catid items from the contentitem tag map table
$recipe_catid_condition = array( $db->quoteName('type_alias') . ' = '. $db->quote('com_recipe_manager.recipe.category') );
// [Interpretation 8335] Create a new query object.
$query = $db->getQuery(true);
$query->delete($db->quoteName('#__contentitem_tag_map'));
$query->where($recipe_catid_condition);
$db->setQuery($query);
// [Interpretation 8345] Execute the query to remove Recipe catid items
$recipe_catid_done = $db->execute();
if ($recipe_catid_done)
{
// [Interpretation 8353] If successfully remove Recipe catid add queued success message.
$app->enqueueMessage(JText::_('The (com_recipe_manager.recipe.category) type alias was removed from the <b>#__contentitem_tag_map</b> table'));
}
// [Interpretation 8364] Remove Recipe catid items from the ucm content table
$recipe_catid_condition = array( $db->quoteName('core_type_alias') . ' = ' . $db->quote('com_recipe_manager.recipe.category') );
// [Interpretation 8370] Create a new query object.
$query = $db->getQuery(true);
$query->delete($db->quoteName('#__ucm_content'));
$query->where($recipe_catid_condition);
$db->setQuery($query);
// [Interpretation 8380] Execute the query to remove Recipe catid items
$recipe_catid_done = $db->execute();
if ($recipe_catid_done)
{
// [Interpretation 8388] If successfully removed Recipe catid add queued success message.
$app->enqueueMessage(JText::_('The (com_recipe_manager.recipe.category) type alias was removed from the <b>#__ucm_content</b> table'));
}
// [Interpretation 8399] Make sure that all the Recipe catid items are cleared from DB
foreach ($recipe_catid_ids as $recipe_catid_id)
{
// [Interpretation 8407] Remove Recipe catid items from the ucm base table
$recipe_catid_condition = array( $db->quoteName('ucm_type_id') . ' = ' . $recipe_catid_id);
// [Interpretation 8414] Create a new query object.
$query = $db->getQuery(true);
$query->delete($db->quoteName('#__ucm_base'));
$query->where($recipe_catid_condition);
$db->setQuery($query);
// [Interpretation 8424] Execute the query to remove Recipe catid items
$db->execute();
// [Interpretation 8431] Remove Recipe catid items from the ucm history table
$recipe_catid_condition = array( $db->quoteName('ucm_type_id') . ' = ' . $recipe_catid_id);
// [Interpretation 8437] Create a new query object.
$query = $db->getQuery(true);
$query->delete($db->quoteName('#__ucm_history'));
$query->where($recipe_catid_condition);
$db->setQuery($query);
// [Interpretation 8447] Execute the query to remove Recipe catid items
$db->execute();
}
}
// [Interpretation 8458] If All related items was removed queued success message.
$app->enqueueMessage(JText::_('All related items was removed from the <b>#__ucm_base</b> table'));
$app->enqueueMessage(JText::_('All related items was removed from the <b>#__ucm_history</b> table'));
// [Interpretation 8467] Remove recipe_manager assets from the assets table
$recipe_manager_condition = array( $db->quoteName('name') . ' LIKE ' . $db->quote('com_recipe_manager%') );
// [Interpretation 8473] Create a new query object.
$query = $db->getQuery(true);
$query->delete($db->quoteName('#__assets'));
$query->where($recipe_manager_condition);
$db->setQuery($query);
$recipe_catid_done = $db->execute();
if ($recipe_catid_done)
{
// [Interpretation 8486] If successfully removed recipe_manager add queued success message.
$app->enqueueMessage(JText::_('All related items was removed from the <b>#__assets</b> table'));
}
// little notice as after service, in case of bad experience with component.
echo '<h2>Did something go wrong? Are you disappointed?</h2>
<p>Please let me know at <a href="mailto:[email protected]">[email protected]</a>.
<br />We at Vast Development Method are committed to building extensions that performs proficiently! You can help us, really!
<br />Send me your thoughts on improvements that is needed, trust me, I will be very grateful!
<br />Visit us at <a href="https://www.vdm.io" target="_blank">https://www.vdm.io</a> today!</p>';
}
/**
* Called on update
*
* @param JAdapterInstance $parent The object responsible for running this script
*
* @return boolean True on success
*/
public function update(JAdapterInstance $parent){}
/**
* Called before any type of action
*
* @param string $type Which action is happening (install|uninstall|discover_install|update)
* @param JAdapterInstance $parent The object responsible for running this script
*
* @return boolean True on success
*/
public function preflight($type, JAdapterInstance $parent)
{
// get application
$app = JFactory::getApplication();
// is redundant or so it seems ...hmmm let me know if it works again
if ($type === 'uninstall')
{
return true;
}
// the default for both install and update
$jversion = new JVersion();
if (!$jversion->isCompatible('3.8.0'))
{
$app->enqueueMessage('Please upgrade to at least Joomla! 3.8.0 before continuing!', 'error');
return false;
}
// do any updates needed
if ($type === 'update')
{
}
// do any install needed
if ($type === 'install')
{
}
// check if the PHPExcel stuff is still around
if (JFile::exists(JPATH_ADMINISTRATOR . '/components/com_recipe_manager/helpers/PHPExcel.php'))
{
// We need to remove this old PHPExcel folder
$this->removeFolder(JPATH_ADMINISTRATOR . '/components/com_recipe_manager/helpers/PHPExcel');
// We need to remove this old PHPExcel file
JFile::delete(JPATH_ADMINISTRATOR . '/components/com_recipe_manager/helpers/PHPExcel.php');
}
return true;
}
/**
* Called after any type of action
*
* @param string $type Which action is happening (install|uninstall|discover_install|update)
* @param JAdapterInstance $parent The object responsible for running this script
*
* @return boolean True on success
*/
public function postflight($type, JAdapterInstance $parent)
{
// get application
$app = JFactory::getApplication();
// [Interpretation 8662] We check if we have dynamic folders to copy
$this->setDynamicF0ld3rs($app, $parent);
// set the default component settings
if ($type === 'install')
{
// [Interpretation 7801] Get The Database object
$db = JFactory::getDbo();
// [Interpretation 7810] Create the ingredient content type object.
$ingredient = new stdClass();
$ingredient->type_title = 'Recipe_manager Ingredient';
$ingredient->type_alias = 'com_recipe_manager.ingredient';
$ingredient->table = '{"special": {"dbtable": "#__recipe_manager_ingredient","key": "id","type": "Ingredient","prefix": "recipe_managerTable","config": "array()"},"common": {"dbtable": "#__ucm_content","key": "ucm_id","type": "Corecontent","prefix": "JTable","config": "array()"}}';
$ingredient->field_mappings = '{"common": {"core_content_item_id": "id","core_title": "name","core_state": "published","core_alias": "null","core_created_time": "created","core_modified_time": "modified","core_body": "null","core_hits": "hits","core_publish_up": "null","core_publish_down": "null","core_access": "access","core_params": "params","core_featured": "null","core_metadata": "null","core_language": "null","core_images": "null","core_urls": "null","core_version": "version","core_ordering": "ordering","core_metakey": "null","core_metadesc": "null","core_catid": "null","core_xreference": "null","asset_id": "asset_id"},"special": {"name":"name","unit":"unit","image":"image"}}';
$ingredient->router = 'Recipe_managerHelperRoute::getIngredientRoute';
$ingredient->content_history_options = '{"formFile": "administrator/components/com_recipe_manager/models/forms/ingredient.xml","hideFields": ["asset_id","checked_out","checked_out_time","version"],"ignoreChanges": ["modified_by","modified","checked_out","checked_out_time","version","hits"],"convertToInt": ["published","ordering"],"displayLookup": [{"sourceColumn": "created_by","targetTable": "#__users","targetColumn": "id","displayColumn": "name"},{"sourceColumn": "access","targetTable": "#__viewlevels","targetColumn": "id","displayColumn": "title"},{"sourceColumn": "modified_by","targetTable": "#__users","targetColumn": "id","displayColumn": "name"}]}';
// [Interpretation 7843] Set the object into the content types table.
$ingredient_Inserted = $db->insertObject('#__content_types', $ingredient);
// [Interpretation 7810] Create the recipe content type object.
$recipe = new stdClass();
$recipe->type_title = 'Recipe_manager Recipe';
$recipe->type_alias = 'com_recipe_manager.recipe';
$recipe->table = '{"special": {"dbtable": "#__recipe_manager_recipe","key": "id","type": "Recipe","prefix": "recipe_managerTable","config": "array()"},"common": {"dbtable": "#__ucm_content","key": "ucm_id","type": "Corecontent","prefix": "JTable","config": "array()"}}';
$recipe->field_mappings = '{"common": {"core_content_item_id": "id","core_title": "name","core_state": "published","core_alias": "alias","core_created_time": "created","core_modified_time": "modified","core_body": "null","core_hits": "hits","core_publish_up": "null","core_publish_down": "null","core_access": "access","core_params": "params","core_featured": "null","core_metadata": "null","core_language": "null","core_images": "null","core_urls": "null","core_version": "version","core_ordering": "ordering","core_metakey": "null","core_metadesc": "null","core_catid": "catid","core_xreference": "null","asset_id": "asset_id"},"special": {"name":"name","alias":"alias","preparing_time":"preparing_time","image":"image","description":"description"}}';
$recipe->router = 'Recipe_managerHelperRoute::getRecipeRoute';
$recipe->content_history_options = '{"formFile": "administrator/components/com_recipe_manager/models/forms/recipe.xml","hideFields": ["asset_id","checked_out","checked_out_time","version"],"ignoreChanges": ["modified_by","modified","checked_out","checked_out_time","version","hits"],"convertToInt": ["published","ordering","catid","preparing_time"],"displayLookup": [{"sourceColumn": "catid","targetTable": "#__categories","targetColumn": "id","displayColumn": "title"},{"sourceColumn": "created_by","targetTable": "#__users","targetColumn": "id","displayColumn": "name"},{"sourceColumn": "access","targetTable": "#__viewlevels","targetColumn": "id","displayColumn": "title"},{"sourceColumn": "modified_by","targetTable": "#__users","targetColumn": "id","displayColumn": "name"}]}';
// [Interpretation 7843] Set the object into the content types table.
$recipe_Inserted = $db->insertObject('#__content_types', $recipe);
// [Interpretation 7810] Create the recipe category content type object.
$recipe_category = new stdClass();
$recipe_category->type_title = 'Recipe_manager Recipe Catid';
$recipe_category->type_alias = 'com_recipe_manager.recipe.category';
$recipe_category->table = '{"special":{"dbtable":"#__categories","key":"id","type":"Category","prefix":"JTable","config":"array()"},"common":{"dbtable":"#__ucm_content","key":"ucm_id","type":"Corecontent","prefix":"JTable","config":"array()"}}';
$recipe_category->field_mappings = '{"common":{"core_content_item_id":"id","core_title":"title","core_state":"published","core_alias":"alias","core_created_time":"created_time","core_modified_time":"modified_time","core_body":"description", "core_hits":"hits","core_publish_up":"null","core_publish_down":"null","core_access":"access", "core_params":"params", "core_featured":"null", "core_metadata":"metadata", "core_language":"language", "core_images":"null", "core_urls":"null", "core_version":"version", "core_ordering":"null", "core_metakey":"metakey", "core_metadesc":"metadesc", "core_catid":"parent_id", "core_xreference":"null", "asset_id":"asset_id"}, "special":{"parent_id":"parent_id","lft":"lft","rgt":"rgt","level":"level","path":"path","extension":"extension","note":"note"}}';
$recipe_category->router = 'Recipe_managerHelperRoute::getCategoryRoute';
$recipe_category->content_history_options = '{"formFile":"administrator\/components\/com_categories\/models\/forms\/category.xml", "hideFields":["asset_id","checked_out","checked_out_time","version","lft","rgt","level","path","extension"], "ignoreChanges":["modified_user_id", "modified_time", "checked_out", "checked_out_time", "version", "hits", "path"],"convertToInt":["publish_up", "publish_down"], "displayLookup":[{"sourceColumn":"created_user_id","targetTable":"#__users","targetColumn":"id","displayColumn":"name"},{"sourceColumn":"access","targetTable":"#__viewlevels","targetColumn":"id","displayColumn":"title"},{"sourceColumn":"modified_user_id","targetTable":"#__users","targetColumn":"id","displayColumn":"name"},{"sourceColumn":"parent_id","targetTable":"#__categories","targetColumn":"id","displayColumn":"title"}]}';
// [Interpretation 7843] Set the object into the content types table.
$recipe_category_Inserted = $db->insertObject('#__content_types', $recipe_category);
// [Interpretation 7934] Install the global extenstion params.
$query = $db->getQuery(true);
// [Interpretation 7947] Field to update.
$fields = array(
$db->quoteName('params') . ' = ' . $db->quote('{"autorName":"Oh Martin","autorEmail":"[email protected]","check_in":"-1 day","save_history":"1","history_limit":"10"}'),
);
// [Interpretation 7954] Condition.
$conditions = array(
$db->quoteName('element') . ' = ' . $db->quote('com_recipe_manager')
);
$query->update($db->quoteName('#__extensions'))->set($fields)->where($conditions);
$db->setQuery($query);
$allDone = $db->execute();
echo '<a target="_blank" href="https://www.vdm.io" title="Recipe Manager">
<img src="components/com_recipe_manager/assets/images/vdm-component.png"/>
</a>';
}
// do any updates needed
if ($type === 'update')
{
// [Interpretation 7801] Get The Database object
$db = JFactory::getDbo();
// [Interpretation 7810] Create the ingredient content type object.
$ingredient = new stdClass();
$ingredient->type_title = 'Recipe_manager Ingredient';
$ingredient->type_alias = 'com_recipe_manager.ingredient';
$ingredient->table = '{"special": {"dbtable": "#__recipe_manager_ingredient","key": "id","type": "Ingredient","prefix": "recipe_managerTable","config": "array()"},"common": {"dbtable": "#__ucm_content","key": "ucm_id","type": "Corecontent","prefix": "JTable","config": "array()"}}';
$ingredient->field_mappings = '{"common": {"core_content_item_id": "id","core_title": "name","core_state": "published","core_alias": "null","core_created_time": "created","core_modified_time": "modified","core_body": "null","core_hits": "hits","core_publish_up": "null","core_publish_down": "null","core_access": "access","core_params": "params","core_featured": "null","core_metadata": "null","core_language": "null","core_images": "null","core_urls": "null","core_version": "version","core_ordering": "ordering","core_metakey": "null","core_metadesc": "null","core_catid": "null","core_xreference": "null","asset_id": "asset_id"},"special": {"name":"name","unit":"unit","image":"image"}}';
$ingredient->router = 'Recipe_managerHelperRoute::getIngredientRoute';
$ingredient->content_history_options = '{"formFile": "administrator/components/com_recipe_manager/models/forms/ingredient.xml","hideFields": ["asset_id","checked_out","checked_out_time","version"],"ignoreChanges": ["modified_by","modified","checked_out","checked_out_time","version","hits"],"convertToInt": ["published","ordering"],"displayLookup": [{"sourceColumn": "created_by","targetTable": "#__users","targetColumn": "id","displayColumn": "name"},{"sourceColumn": "access","targetTable": "#__viewlevels","targetColumn": "id","displayColumn": "title"},{"sourceColumn": "modified_by","targetTable": "#__users","targetColumn": "id","displayColumn": "name"}]}';
// [Interpretation 7823] Check if ingredient type is already in content_type DB.
$ingredient_id = null;
$query = $db->getQuery(true);
$query->select($db->quoteName(array('type_id')));
$query->from($db->quoteName('#__content_types'));
$query->where($db->quoteName('type_alias') . ' LIKE '. $db->quote($ingredient->type_alias));
$db->setQuery($query);
$db->execute();
// [Interpretation 7843] Set the object into the content types table.
if ($db->getNumRows())
{
$ingredient->type_id = $db->loadResult();
$ingredient_Updated = $db->updateObject('#__content_types', $ingredient, 'type_id');
}
else
{
$ingredient_Inserted = $db->insertObject('#__content_types', $ingredient);
}
// [Interpretation 7810] Create the recipe content type object.
$recipe = new stdClass();
$recipe->type_title = 'Recipe_manager Recipe';
$recipe->type_alias = 'com_recipe_manager.recipe';
$recipe->table = '{"special": {"dbtable": "#__recipe_manager_recipe","key": "id","type": "Recipe","prefix": "recipe_managerTable","config": "array()"},"common": {"dbtable": "#__ucm_content","key": "ucm_id","type": "Corecontent","prefix": "JTable","config": "array()"}}';
$recipe->field_mappings = '{"common": {"core_content_item_id": "id","core_title": "name","core_state": "published","core_alias": "alias","core_created_time": "created","core_modified_time": "modified","core_body": "null","core_hits": "hits","core_publish_up": "null","core_publish_down": "null","core_access": "access","core_params": "params","core_featured": "null","core_metadata": "null","core_language": "null","core_images": "null","core_urls": "null","core_version": "version","core_ordering": "ordering","core_metakey": "null","core_metadesc": "null","core_catid": "catid","core_xreference": "null","asset_id": "asset_id"},"special": {"name":"name","alias":"alias","preparing_time":"preparing_time","image":"image","description":"description"}}';
$recipe->router = 'Recipe_managerHelperRoute::getRecipeRoute';
$recipe->content_history_options = '{"formFile": "administrator/components/com_recipe_manager/models/forms/recipe.xml","hideFields": ["asset_id","checked_out","checked_out_time","version"],"ignoreChanges": ["modified_by","modified","checked_out","checked_out_time","version","hits"],"convertToInt": ["published","ordering","catid","preparing_time"],"displayLookup": [{"sourceColumn": "catid","targetTable": "#__categories","targetColumn": "id","displayColumn": "title"},{"sourceColumn": "created_by","targetTable": "#__users","targetColumn": "id","displayColumn": "name"},{"sourceColumn": "access","targetTable": "#__viewlevels","targetColumn": "id","displayColumn": "title"},{"sourceColumn": "modified_by","targetTable": "#__users","targetColumn": "id","displayColumn": "name"}]}';
// [Interpretation 7823] Check if recipe type is already in content_type DB.
$recipe_id = null;
$query = $db->getQuery(true);
$query->select($db->quoteName(array('type_id')));
$query->from($db->quoteName('#__content_types'));
$query->where($db->quoteName('type_alias') . ' LIKE '. $db->quote($recipe->type_alias));
$db->setQuery($query);
$db->execute();
// [Interpretation 7843] Set the object into the content types table.
if ($db->getNumRows())
{
$recipe->type_id = $db->loadResult();
$recipe_Updated = $db->updateObject('#__content_types', $recipe, 'type_id');
}
else
{
$recipe_Inserted = $db->insertObject('#__content_types', $recipe);
}
// [Interpretation 7810] Create the recipe category content type object.
$recipe_category = new stdClass();
$recipe_category->type_title = 'Recipe_manager Recipe Catid';
$recipe_category->type_alias = 'com_recipe_manager.recipe.category';
$recipe_category->table = '{"special":{"dbtable":"#__categories","key":"id","type":"Category","prefix":"JTable","config":"array()"},"common":{"dbtable":"#__ucm_content","key":"ucm_id","type":"Corecontent","prefix":"JTable","config":"array()"}}';
$recipe_category->field_mappings = '{"common":{"core_content_item_id":"id","core_title":"title","core_state":"published","core_alias":"alias","core_created_time":"created_time","core_modified_time":"modified_time","core_body":"description", "core_hits":"hits","core_publish_up":"null","core_publish_down":"null","core_access":"access", "core_params":"params", "core_featured":"null", "core_metadata":"metadata", "core_language":"language", "core_images":"null", "core_urls":"null", "core_version":"version", "core_ordering":"null", "core_metakey":"metakey", "core_metadesc":"metadesc", "core_catid":"parent_id", "core_xreference":"null", "asset_id":"asset_id"}, "special":{"parent_id":"parent_id","lft":"lft","rgt":"rgt","level":"level","path":"path","extension":"extension","note":"note"}}';
$recipe_category->router = 'Recipe_managerHelperRoute::getCategoryRoute';
$recipe_category->content_history_options = '{"formFile":"administrator\/components\/com_categories\/models\/forms\/category.xml", "hideFields":["asset_id","checked_out","checked_out_time","version","lft","rgt","level","path","extension"], "ignoreChanges":["modified_user_id", "modified_time", "checked_out", "checked_out_time", "version", "hits", "path"],"convertToInt":["publish_up", "publish_down"], "displayLookup":[{"sourceColumn":"created_user_id","targetTable":"#__users","targetColumn":"id","displayColumn":"name"},{"sourceColumn":"access","targetTable":"#__viewlevels","targetColumn":"id","displayColumn":"title"},{"sourceColumn":"modified_user_id","targetTable":"#__users","targetColumn":"id","displayColumn":"name"},{"sourceColumn":"parent_id","targetTable":"#__categories","targetColumn":"id","displayColumn":"title"}]}';
// [Interpretation 7823] Check if recipe category type is already in content_type DB.
$recipe_category_id = null;
$query = $db->getQuery(true);
$query->select($db->quoteName(array('type_id')));
$query->from($db->quoteName('#__content_types'));
$query->where($db->quoteName('type_alias') . ' LIKE '. $db->quote($recipe_category->type_alias));
$db->setQuery($query);
$db->execute();
// [Interpretation 7843] Set the object into the content types table.
if ($db->getNumRows())
{
$recipe_category->type_id = $db->loadResult();
$recipe_category_Updated = $db->updateObject('#__content_types', $recipe_category, 'type_id');
}
else
{
$recipe_category_Inserted = $db->insertObject('#__content_types', $recipe_category);
}
echo '<a target="_blank" href="https://www.vdm.io" title="Recipe Manager">
<img src="components/com_recipe_manager/assets/images/vdm-component.png"/>
</a>
<h3>Upgrade to Version 1.0.2 Was Successful! Let us know if anything is not working as expected.</h3>';
}
return true;
}
/**
* Remove folders with files
*
* @param string $dir The path to folder to remove
* @param boolean $ignore The folders and files to ignore and not remove
*
* @return boolean True in all is removed
*
*/
protected function removeFolder($dir, $ignore = false)
{
if (JFolder::exists($dir))
{
$it = new RecursiveDirectoryIterator($dir);
$it = new RecursiveIteratorIterator($it, RecursiveIteratorIterator::CHILD_FIRST);
// remove ending /
$dir = rtrim($dir, '/');
// now loop the files & folders
foreach ($it as $file)
{
if ('.' === $file->getBasename() || '..' === $file->getBasename()) continue;
// set file dir
$file_dir = $file->getPathname();
// check if this is a dir or a file
if ($file->isDir())
{
$keeper = false;
if ($this->checkArray($ignore))
{
foreach ($ignore as $keep)
{
if (strpos($file_dir, $dir.'/'.$keep) !== false)
{
$keeper = true;
}
}
}
if ($keeper)
{
continue;
}
JFolder::delete($file_dir);
}
else
{
$keeper = false;
if ($this->checkArray($ignore))
{
foreach ($ignore as $keep)
{
if (strpos($file_dir, $dir.'/'.$keep) !== false)
{
$keeper = true;
}
}
}
if ($keeper)
{
continue;
}
JFile::delete($file_dir);
}
}
// delete the root folder if not ignore found
if (!$this->checkArray($ignore))
{
return JFolder::delete($dir);
}
return true;
}
return false;
}
/**
* Check if have an array with a length
*
* @input array The array to check
*
* @returns bool/int number of items in array on success
*/
protected function checkArray($array, $removeEmptyString = false)
{
if (isset($array) && is_array($array) && ($nr = count((array)$array)) > 0)
{
// also make sure the empty strings are removed
if ($removeEmptyString)
{
foreach ($array as $key => $string)
{
if (empty($string))
{
unset($array[$key]);
}
}
return $this->checkArray($array, false);
}
return $nr;
}
return false;
}
/**
* Method to set/copy dynamic folders into place (use with caution)
*
* @return void
*/
protected function setDynamicF0ld3rs($app, $parent)
{
// [Interpretation 8689] get the instalation path
$installer = $parent->getParent();
$installPath = $installer->getPath('source');
// [Interpretation 8694] get all the folders
$folders = JFolder::folders($installPath);
// [Interpretation 8698] check if we have folders we may want to copy
$doNotCopy = array('media','admin','site'); // Joomla already deals with these
if (count((array) $folders) > 1)
{
foreach ($folders as $folder)
{
// [Interpretation 8706] Only copy if not a standard folders
if (!in_array($folder, $doNotCopy))
{
// [Interpretation 8710] set the source path
$src = $installPath.'/'.$folder;
// [Interpretation 8713] set the destination path
$dest = JPATH_ROOT.'/'.$folder;
// [Interpretation 8716] now try to copy the folder
if (!JFolder::copy($src, $dest, '', true))
{
$app->enqueueMessage('Could not copy '.$folder.' folder into place, please make sure destination is writable!', 'error');
}
}
}
}
}
}