-
Notifications
You must be signed in to change notification settings - Fork 7
/
script.php
753 lines (651 loc) · 30 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
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
<?php
define('MODIFIED', 1);
define('NOT_MODIFIED', 2);
/**
* Updates the database structure of the component
*
* @version 0.2b
*/
class com_citybrandingInstallerScript {
private $citybranding_version = 0;
/**
* Method called before install/update the component. Note: This method won't be called during uninstall process.
* @param string $type Type of process [install | update]
* @param mixed $parent Object who called this method
* @return boolean True if the process should continue, false otherwise
*/
public function preflight($type, $parent) {
$jversion = new JVersion();
// Installing component manifest file version
$manifest = $parent->get("manifest");
$this->release = (string) $manifest['version'];
$this->citybranding_version = $parent->get( "manifest" )->version;
// abort if the component wasn't build for the current Joomla version
if (!$jversion->isCompatible($this->release)) {
JFactory::getApplication()->enqueueMessage(JText::_('This component is not compatible with installed Joomla version'), 'error');
return false;
}
// abort if the component being installed is older than the currently installed version
if ( $type == 'update' ) {
$oldRelease = $this->getParam('version');
$rel = $oldRelease . ' to ' . $this->citybranding_version;
if ( version_compare( $this->citybranding_version, $oldRelease, 'lt' ) ) {
Jerror::raiseWarning(null, 'Incorrect version sequence. Cannot upgrade ' . $rel);
return false;
}
}
}
/**
* Method to install the component
* @param mixed $parent Object who called this method.
*/
public function install($parent) {
$this->installDb($parent);
$this->installPlugins($parent);
$this->installModules($parent);
}
/**
* Method to update the component
* @param mixed $parent Object who called this method.
*/
public function update($parent) {
$this->installDb($parent);
$this->installPlugins($parent);
$this->installModules($parent);
}
/**
* Method to uninstall the component
* @param mixed $parent Object who called this method.
*/
public function uninstall($parent) {
$this->uninstallPlugins($parent);
$this->uninstallModules($parent);
}
/**
* Installs plugins for this component
* @param mixed $parent Object who called the install/update method
*/
private function installPlugins($parent) {
$installation_folder = $parent->getParent()->getPath('source');
$app = JFactory::getApplication();
$plugins = $parent->get("manifest")->plugins;
if (count($plugins->children())) {
$db = JFactory::getDbo();
$query = $db->getQuery(true);
foreach ($plugins->children() as $plugin) {
$pname = (string) $plugin['plugin'];
$pgroup = (string) $plugin['group'];
$path = $installation_folder . '/plugins/' . $pgroup;
$installer = new JInstaller;
if (!$this->isAlreadyInstalled('plugin', $pname, $pgroup)) {
$result = $installer->install($path);
} else {
$result = $installer->update($path);
}
if ($result) {
$app->enqueueMessage('Plugin ' . $pname . ' was installed successfully');
} else {
$app->enqueueMessage('There was an poi installing the plugin ' . $pname, 'error');
}
$query
->clear()
->update('#__extensions')
->set('enabled = 1')
->where(
array(
'type LIKE ' . $db->quote('plugin'),
'element LIKE ' . $db->quote($pname),
'folder LIKE ' . $db->quote($pgroup)
)
);
$db->setQuery($query);
$db->query();
}
}
}
/**
* Uninstalls plugins
* @param mixed $parent Object who called the uninstall method
*/
private function uninstallPlugins($parent) {
$db = JFactory::getDBO();
$app = JFactory::getApplication();
$plugins = $parent->get("manifest")->plugins;
if (count($plugins->children())) {
$db = JFactory::getDbo();
$query = $db->getQuery(true);
foreach ($plugins->children() as $plugin) {
$pname = (string) $plugin['plugin'];
$pgroup = (string) $plugin['group'];
$query
->clear()
->select('extension_id')
->from('#__extensions')
->where(
array(
'type LIKE ' . $db->quote('plugin'),
'element LIKE ' . $db->quote($pname),
'folder LIKE ' . $db->quote($pgroup)
)
);
$db->setQuery($query);
$extension = $db->loadResult();
if (!empty($extension)) {
$installer = new JInstaller;
$result = $installer->uninstall('plugin', $extension);
if ($result) {
$app->enqueueMessage('Plugin ' . $pname . ' was uninstalled successfully');
} else {
$app->enqueueMessage('There was an poi uninstalling the plugin ' . $pname, 'error');
}
}
}
}
}
/**
* Installs plugins for this component
* @param mixed $parent Object who called the install/update method
*/
private function installModules($parent) {
$installation_folder = $parent->getParent()->getPath('source');
$app = JFactory::getApplication();
if (!empty($parent->get("manifest")->modules)) {
$modules = $parent->get("manifest")->modules;
if (count($modules->children())) {
foreach ($modules->children() as $module) {
$moduleName = (string) $module['module'];
$path = $installation_folder . '/modules/' . $moduleName;
$installer = new JInstaller;
if (!$this->isAlreadyInstalled('module', $moduleName)) {
$result = $installer->install($path);
} else {
$result = $installer->update($path);
}
if ($result) {
$app->enqueueMessage('Module ' . $moduleName . ' was installed successfully');
} else {
$app->enqueueMessage('There was an poi installing the module ' . $moduleName, 'error');
}
}
}
}
}
/**
* Uninstalls plugins
* @param mixed $parent Object who called the uninstall method
*/
private function uninstallModules($parent) {
$db = JFactory::getDBO();
$app = JFactory::getApplication();
if (!empty($parent->get("manifest")->modules)) {
$modules = $parent->get("manifest")->modules;
if (count($modules->children())) {
$db = JFactory::getDbo();
$query = $db->getQuery(true);
foreach ($modules->children() as $plugin) {
$moduleName = (string) $plugin['module'];
$query
->clear()
->select('extension_id')
->from('#__extensions')
->where(
array(
'type LIKE ' . $db->quote('module'),
'element LIKE ' . $db->quote($moduleName)
)
);
$db->setQuery($query);
$extension = $db->loadResult();
if (!empty($extension)) {
$installer = new JInstaller;
$result = $installer->uninstall('module', $extension);
if ($result) {
$app->enqueueMessage('Module ' . $moduleName . ' was uninstalled successfully');
} else {
$app->enqueueMessage('There was an poi uninstalling the module ' . $moduleName, 'error');
}
}
}
}
}
}
/**
* Check if an extension is already installed in the system
* @param string $type
* @param string $name
* @param mixed $folder
* @return type
*/
private function isAlreadyInstalled($type, $name, $folder = null) {
$result = false;
switch ($type) {
case 'plugin':
$result = file_exists(JPATH_PLUGINS . '/' . $folder . '/' . $name);
break;
case 'module':
$result = file_exists(JPATH_SITE . '/modules/' . $name);
break;
}
return $result;
}
/**
* Method to update the DB of the component
* @param mixed $parent Object who started the upgrading process
*/
private function installDb($parent) {
$installation_folder = $parent->getParent()->getPath('source');
$app = JFactory::getApplication();
if (function_exists('simplexml_load_file')) {
$component_data = simplexml_load_file($installation_folder . '/administrator/installer/structure.xml');
//Check if there are tables to import.
foreach ($component_data->children() as $table) {
$this->processTable($app, $table);
}
} else {
$app->enqueueMessage(JText::_('This script needs \'simplexml_load_file\' to update the component'));
}
}
/**
* Process a table
* @param JApplicationCms $app Application object
* @param SimpleXMLElement $table Table to process
*/
private function processTable($app, $table) {
$db = JFactory::getDbo();
$table_added = false;
if (isset($table['action'])) {
switch ($table['action']) {
case 'add':
//Check if the table exists before create the statement
if (!$this->existsTable($table['table_name'])) {
$create_statement = $this->generateCreateTableStatement($table);
$db->setQuery($create_statement);
try {
$db->execute();
$app->enqueueMessage(JText::sprintf('Table `%s` has been succesfully created', (string) $table['table_name']));
$table_added = true;
} catch (Exception $ex) {
$app->enqueueMessage(JText::sprintf('There was an error creating the table `%s`. Error: %s', (string) $table['table_name'], $ex->getMessage()), 'error');
}
}
break;
case 'change':
//Check if the table exists first to avoid errors.
if ($this->existsTable($table['old_name']) && !$this->existsTable($table['new_name'])) {
try {
$db->renameTable($table['old_name'], $table['new_name']);
$app->enqueueMessage(JText::sprintf('Table `%s` was succesfully renamed to `%s`', $table['old_name'], $table['new_name']));
} catch (Exception $ex) {
$app->enqueueMessage(JText::sprintf('There was an error renaming the table `%s`. Error: %s', $table['old_name'], $ex->getMessage()), 'error');
}
} else {
if (!$this->existsTable($table['table_name'])) {
//If the table does not exists, let's create it.
$create_statement = $this->generateCreateTableStatement($table);
$db->setQuery($create_statement);
try {
$db->execute();
$app->enqueueMessage(JText::sprintf('Table `%s` has been succesfully created', $table['table_name']));
$table_added = true;
} catch (Exception $ex) {
$app->enqueueMessage(JText::sprintf('There was an error creating the table `%s`. Error: %s', $table['table_name'], $ex->getMessage()), 'error');
}
}
}
break;
case 'remove':
try {
//We make sure that the table will be removed only if it exists specifying ifExists argument as true.
$db->dropTable($table['table_name'], true);
$app->enqueueMessage(JText::sprintf('Table `%s` was succesfully deleted', $table['table_name']));
} catch (Exception $ex) {
$app->enqueueMessage(JText::sprintf('There was an error deleting Table `%s`. Error: %s', $table['table_name'], $ex->getMessage()), 'error');
}
break;
}
}
//If the table wasn't added before, let's process the fields of the table
if (!$table_added) {
$this->executeFieldsUpdating($app, $table);
}
}
/**
* Generates a 'CREATE TABLE' statement for the tables passed by argument.
* @param SimpleXMLElement $table Table of the database
* @return string 'CREATE TABLE' statement
*/
private function generateCreateTableStatement($table) {
$create_table_statement = '';
if (isset($table->field)) {
$fields = $table->children();
$fields_definitions = array();
$indexes = array();
$db = JFactory::getDbo();
foreach ($fields as $field) {
$fields_definitions[] = $this->generateColumnDeclaration($field);
if ($field['index'] == 'index') {
$indexes[] = $field['field_name'];
}
}
foreach ($indexes as $index) {
$fields_definitions[] = JText::sprintf('INDEX %s (%s ASC)', $db->quoteName((string) $index), $index);
}
$create_table_statement = JText::sprintf('CREATE TABLE IF NOT EXISTS %s (%s)', $table['table_name'], implode(',', $fields_definitions));
}
return $create_table_statement;
}
/**
* Updates all the fields related to a table.
* @param SimpleXMLElement $table Table information.
*/
private function executeFieldsUpdating($app, $table) {
if (isset($table->field)) {
foreach ($table->children() as $field) {
$this->processField($app, $table['table_name'], $field);
}
}
}
/**
* Process a certain field.
* @param JApplicationCms $app Application object
* @param string $table_name The name of the table that contains the field.
* @param SimpleXMLElement $field Field Information.
*/
private function processField($app, $table_name, $field) {
$db = JFactory::getDbo();
if (isset($field['action'])) {
switch ($field['action']) {
case 'add':
$result = $this->addField($table_name, $field);
if ($result === MODIFIED) {
$app->enqueueMessage(JText::sprintf('Field `%s` has been succesfully added', $field['field_name']));
} else if ($result !== NOT_MODIFIED) {
$app->enqueueMessage(JText::sprintf('There was an error adding the field `%s`. Error: %s', $field['field_name'], $result), 'error');
}
break;
case 'change':
if (isset($field['old_name']) && isset($field['new_name'])) {
if ($this->existsField($table_name, $field['old_name'])) {
$renaming_statement = JText::sprintf('ALTER TABLE %s CHANGE %s %s %s', $table_name, $field['old_name'], $field['new_name'], $this->getFieldType($field));
$db->setQuery($renaming_statement);
try {
$db->execute();
$app->enqueueMessage(JText::sprintf('Field `%s` has been succesfully modified', $field['old_name']));
} catch (Exception $ex) {
$app->enqueueMessage(JText::sprintf('There was an error modifying the field `%s`. Error: %s', $field['field_name'], $ex->getMessage()), 'error');
}
} else {
$result = $this->addField($table_name, $field);
if ($result === MODIFIED) {
$app->enqueueMessage(JText::sprintf('Field `%s` has been succesfully modified', $field['field_name']));
} else if ($result !== NOT_MODIFIED) {
$app->enqueueMessage(JText::sprintf('There was an error modifying the field `%s`. Error: %s', $field['field_name'], $result), 'error');
}
}
} else {
$result = $this->addField($table_name, $field);
if ($result === MODIFIED) {
$app->enqueueMessage(JText::sprintf('Field `%s` has been succesfully added', $field['field_name']));
} else if ($result !== NOT_MODIFIED) {
$app->enqueueMessage(JText::sprintf('There was an error adding the field `%s`. Error: %s', $field['field_name'], $result), 'error');
}
}
break;
case 'remove':
//Check if the field exists first to prevent poi removing the field
if ($this->existsField($table_name, $field['field_name'])) {
$drop_statement = JText::sprintf('ALTER TABLE %s DROP COLUMN %s', $table_name, $field['field_name']);
$db->setQuery($drop_statement);
try {
$db->execute();
$app->enqueueMessage(JText::sprintf('Field `%s` has been succesfully deleted', $field['field_name']));
} catch (Exception $ex) {
$app->enqueueMessage(JText::sprintf('There was an error deleting the field `%s`. Error: %s', $field['field_name'], $ex->getMessage()), 'error');
}
}
break;
}
} else {
$result = $this->addField($table_name, $field);
if ($result === MODIFIED) {
$app->enqueueMessage(JText::sprintf('Field `%s` has been succesfully added', $field['field_name']));
} else if ($result !== NOT_MODIFIED) {
$app->enqueueMessage(JText::sprintf('There was an error adding the field `%s`. Error: %s', $field['field_name'], $result), 'error');
}
}
}
/**
* Add a field if it does not exists or modify it if it does.
* @param string $table_name Table name
* @param SimpleXMLElement $field Field Information
* @return mixed Constant on success(self::$MODIFIED | self::$NOT_MODIFIED), error message if an error occurred
*/
private function addField($table_name, $field) {
$db = JFactory::getDbo();
$query_generated = false;
//Check if the field exists first to prevent pois adding the field
if ($this->existsField($table_name, $field['field_name'])) {
if ($this->needsToUpdate($table_name, $field)) {
$change_statement = $this->generateChangeFieldStatement($table_name, $field);
$db->setQuery($change_statement);
$query_generated = true;
}
} else {
$add_statement = $this->generateAddFieldStatement($table_name, $field);
$db->setQuery($add_statement);
$query_generated = true;
}
if ($query_generated) {
try {
$db->execute();
return MODIFIED;
} catch (Exception $ex) {
return $ex->getMessage();
}
}
return NOT_MODIFIED;
}
/**
* Generates an add column statement
* @param string $table_name Table name
* @param SimpleXMLElement $field Field Information
* @return string Add column statement
*/
private function generateAddFieldStatement($table_name, $field) {
$column_declaration = $this->generateColumnDeclaration($field);
return JText::sprintf('ALTER TABLE %s ADD %s', $table_name, $column_declaration);
}
/**
* Generates an change column statement
* @param string $table_name
* @param SimpleXMLElement $field Field Information
* @return string Change column statement
*/
private function generateChangeFieldStatement($table_name, $field) {
$column_declaration = $this->generateColumnDeclaration($field);
return JText::sprintf('ALTER TABLE %s MODIFY %s', $table_name, $column_declaration);
}
/**
* Generate a column declaration
* @param SimpleXMLElement $field
* @return string Column declaration
*/
private function generateColumnDeclaration($field) {
$db = JFactory::getDbo();
$col_name = $db->quoteName((string) $field['field_name']);
$data_type = $this->getFieldType($field);
$default_value = (isset($field['default'])) ? 'DEFAULT ' . $field['default'] : '';
$other_data = '';
if (isset($field['is_autoincrement']) && $field['is_autoincrement'] == 1) {
$other_data .= ' AUTO_INCREMENT';
}
if (isset($field['index'])) {
if ($field['index'] == 'primary') {
$other_data .= ' PRIMARY KEY';
}
}
$comment_value = (isset($field['description'])) ? 'COMMENT ' . $db->quote((string) $field['description']) : '';
return JText::sprintf('%s %s NOT NULL %s %s %s', $col_name, $data_type, $default_value, $other_data, $comment_value);
}
/**
* Generates SQL field type of a field.
* @param SimpleXMLElement $field Field information
* @return string SQL data type
*/
private function getFieldType($field) {
$data_type = (string) $field['field_type'];
if (isset($field['field_length']) && $this->allowsLengthField($data_type)) {
$data_type.= '(' . ((string) $field['field_length']) . ')';
}
return (string) $data_type;
}
/**
* Check if a SQL type allows length values.
* @param string $field_type SQL type
* @return boolean True if it allows length values, false if it does not.
*/
private function allowsLengthField($field_type) {
$allow_lenght = array(
'INT', 'VARCHAR', 'CHAR',
'TINYINT', 'SMALLINT', 'MEDIUMINT',
'INTEGER', 'BIGINT', 'FLOAT',
'DOUBLE', 'DECIMAL', 'NUMERIC'
);
return (in_array((string) $field_type, $allow_lenght));
}
/**
* Checks if a certain exists on the current database
* @param string $table_name Name of the table
* @return boolean True if it exists, false if it does not.
*/
private function existsTable($table_name) {
$db = JFactory::getDbo();
$table_name = str_replace('#__', $db->getPrefix(), (string) $table_name);
return in_array($table_name, $db->getTableList());
}
/**
* Checks if a field exists on a table
* @param string $table_name Table name
* @param string $field_name Field name
* @return boolean True if exists, false if it do
*/
private function existsField($table_name, $field_name) {
$db = JFactory::getDbo();
return in_array((string) $field_name, array_keys($db->getTableColumns($table_name)));
}
/**
* Check if a field needs to be updated.
* @param string $table_name Table name
* @param SimpleXMLElement $field Field information
* @return boolean True if the field has to be updated, false otherwise
*/
private function needsToUpdate($table_name, $field) {
$db = JFactory::getDbo();
$query = JText::sprintf('SHOW FULL COLUMNS FROM %s WHERE Field LIKE %s', $table_name, $db->quote((string) $field['field_name']));
$db->setQuery($query);
$field_info = $db->loadObject();
if (strripos($field_info->Type, $this->getFieldType($field)) === false) {
return true;
} else {
return false;
}
}
/*
* $parent is the class calling this method.
* $type is the type of change (install, update or discover_install, not uninstall).
* postflight is run after the extension is registered in the database.
*/
public function postflight( $type, $parent ) {
// always create or update version parameter
$params['version'] = $this->citybranding_version;
$this->setParams( $params );
$db = JFactory::getDBO();
$query = $db->getQuery(true);
$query
->update('#__update_sites')
->set("`enabled`='1'")
->where("`name`='CityBranding'");
$db->setQuery($query);
$db->execute();
//add root to areas to support nested areas
$this->addRoot();
// Add citybranding content type to support tagging
$this->insert_content_type_brand();
return true;
}
private function insert_content_type_brand()
{
$db = JFactory::getDbo();
// If entries do not exist in #__content_types add them
$query = "SELECT COUNT(*) FROM `#__content_types` ";
$query .= " WHERE type_title IN ('Citybranding Brand') ";
$db->setQuery($query);
$cnt = $db->loadResult();
if ( $cnt == 0 ) {
$query = 'INSERT INTO `#__content_types` ';
$query .= '(`type_title`, `type_alias`, `table`, `rules`, `field_mappings`,`router`) VALUES ';
$query .= "('Citybranding Brand','com_citybranding.brand',";
$query .= '\'{"special":{"dbtable":"#__citybranding_brands","key":"id","type":"brand","prefix":"CitybrandingTable","config":"array()"},"common":{"dbtable":"#__ucm_content","key":"ucm_id","type":"Corecontent","prefix":"JTable","config":"array()"}}\',';
$query .= "'',";
$query .= '\'{"common":{"core_content_item_id":"id","core_title":"title","core_state":"state","core_alias":"null","core_created_by_alias":"null","core_created_time":"created","core_modified_time":"updated","core_body":"description", "core_hits":"hits","core_publish_up":"null","core_publish_down":"null","core_access":"access", "core_params":"null", "core_featured":"null", "core_metadata":"null", "core_language":"language", "core_images":"null", "core_urls":"null", "core_version":"null", "core_ordering":"ordering", "core_metakey":"null", "core_metadesc":"null", "core_catid":"catid", "core_xreference":"null", "asset_id":"asset_id"}, "special":{}}\',';
$query .= "'');";
$db->setQuery($query);
$db->execute();
echo '<p style="color: green;">' . 'Citybranding Brand Content type inserted' . '</p>';
}
}
/*
* get a variable from the manifest file (actually, from the manifest cache).
*/
public function getParam( $name ) {
$db = JFactory::getDbo();
$db->setQuery('SELECT manifest_cache FROM #__extensions WHERE name = "com_citybranding"');
$manifest = json_decode( $db->loadResult(), true );
return $manifest[ $name ];
}
/*
* sets parameter values in the component's row of the extension table
*/
public function setParams($param_array) {
if ( count($param_array) > 0 ) {
// read the existing component value(s)
$db = JFactory::getDbo();
$db->setQuery('SELECT params FROM #__extensions WHERE name = "com_citybranding"');
$params = json_decode( $db->loadResult(), true );
// add the new variable(s) to the existing one(s)
foreach ( $param_array as $name => $value ) {
$params[ (string) $name ] = (string) $value;
}
// store the combined new and existing values back as a JSON string
$paramsString = json_encode( $params );
$db->setQuery('UPDATE #__extensions SET params = ' .
$db->quote( $paramsString ) .
' WHERE name = "com_citybranding"' );
$db->query();
}
}
private function addRoot()
{
$db = JFactory::getDbo();
$sql = 'SELECT COUNT(*) FROM `#__citybranding_areas` WHERE alias = "root"';
$db->setQuery($sql);
$cnt = $db->loadResult();
if( $cnt == 0) {
$sql = 'INSERT INTO `#__citybranding_areas` '
. ' SET parent_id = 0'
. ', lft = 0'
. ', rgt = 1'
. ', level = 0'
. ', title = '.$db->quote( 'Root' )
. ', description = '.$db->quote( 'Root' )
. ', alias = '.$db->quote( 'root' )
. ', access = 1'
. ', path = '.$db->quote( '' )
;
$db->setQuery( $sql );
$db->execute();
echo '<p style="color: green;">' . 'Citybranding Nested Areas prepared' . '</p>';
//return $db->insertid();
}
}
}