GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 423fe8...f48289 )
by gyeong-won
15:56 queued 08:14
created

moduleController::insertUpdatedLog()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 6
nc 2
nop 1
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/* Copyright (C) NAVER <http://www.navercorp.com> */
3
/**
4
 * @class  moduleController
5
 * @author NAVER ([email protected])
6
 * @brief controller class of the module module
7
 */
8
class moduleController extends module
9
{
10
	/**
11
	 * @brief Initialization
12
	 */
13
	function init()
14
	{
15
	}
16
17
	/**
18
	 * @brief Add action forward
19
	 * Action forward finds and forwards if an action is not in the requested module
20
	 * This is used when installing a module
21
	 */
22
	function insertActionForward($module, $type, $act)
23
	{
24
		$args = new stdClass();
25
		$args->module = $module;
26
		$args->type = $type;
27
		$args->act = $act;
28
29
		$output = executeQuery('module.insertActionForward', $args);
30
31
		$oCacheHandler = CacheHandler::getInstance('object', NULL, TRUE);
32
		if($oCacheHandler->isSupport())
33
		{
34
			$cache_key = 'action_forward';
35
			$oCacheHandler->delete($cache_key);
36
		}
37
38
		return $output;
39
	}
40
41
	/**
42
	 * @brief Delete action forward
43
	 */
44
	function deleteActionForward($module, $type, $act)
45
	{
46
		$args = new stdClass();
47
		$args->module = $module;
48
		$args->type = $type;
49
		$args->act = $act;
50
51
		$output = executeQuery('module.deleteActionForward', $args);
52
53
		$oCacheHandler = CacheHandler::getInstance('object', NULL, TRUE);
54
		if($oCacheHandler->isSupport())
55
		{
56
			$cache_key = 'action_forward';
57
			$oCacheHandler->delete($cache_key);
58
		}
59
60
		return $output;
61
	}
62
63
	/**
64
	 * @brief Add module trigger
65
	 * module trigger is to call a trigger to a target module
66
	 *
67
	 */
68 View Code Duplication
	function insertTrigger($trigger_name, $module, $type, $called_method, $called_position)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
69
	{
70
		$args = new stdClass();
71
		$args->trigger_name = $trigger_name;
72
		$args->module = $module;
73
		$args->type = $type;
74
		$args->called_method = $called_method;
75
		$args->called_position = $called_position;
76
77
		$output = executeQuery('module.insertTrigger', $args);
78
		if($output->toBool())
79
		{
80
			//remove from cache
81
			$GLOBALS['__triggers__'] = NULL;
82
			$oCacheHandler = CacheHandler::getInstance('object', NULL, TRUE);
83
			if($oCacheHandler->isSupport())
84
			{
85
				$cache_key = 'triggers';
86
				$oCacheHandler->delete($cache_key);
87
			}
88
		}
89
90
		return $output;
91
	}
92
93
	/**
94
	 * @brief Delete module trigger
95
	 *
96
	 */
97 View Code Duplication
	function deleteTrigger($trigger_name, $module, $type, $called_method, $called_position)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
98
	{
99
		$args = new stdClass();
100
		$args->trigger_name = $trigger_name;
101
		$args->module = $module;
102
		$args->type = $type;
103
		$args->called_method = $called_method;
104
		$args->called_position = $called_position;
105
106
		$output = executeQuery('module.deleteTrigger', $args);
107
		if($output->toBool())
108
		{
109
			//remove from cache
110
			$GLOBALS['__triggers__'] = NULL;
111
			$oCacheHandler = CacheHandler::getInstance('object', NULL, TRUE);
112
			if($oCacheHandler->isSupport())
113
			{
114
				$cache_key = 'triggers';
115
				$oCacheHandler->delete($cache_key);
116
			}
117
		}
118
119
		return $output;
120
	}
121
122
	/**
123
	 * @brief Delete module trigger
124
	 *
125
	 */
126 View Code Duplication
	function deleteModuleTriggers($module)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
127
	{
128
		$args = new stdClass();
129
		$args->module = $module;
130
131
		$output = executeQuery('module.deleteModuleTriggers', $args);
132
		if($output->toBool())
133
		{
134
			//remove from cache
135
			$GLOBALS['__triggers__'] = NULL;
136
			$oCacheHandler = CacheHandler::getInstance('object', NULL, TRUE);
137
			if($oCacheHandler->isSupport())
138
			{
139
				$cache_key = 'triggers';
140
				$oCacheHandler->delete($cache_key);
141
			}
142
		}
143
144
		return $output;
145
	}
146
147
	/**
148
	 * @brief Add module extend
149
	 *
150
	 */
151
	function insertModuleExtend($parent_module, $extend_module, $type, $kind='')
152
	{
153
		if($kind != 'admin') $kind = '';
154
		if(!in_array($type,array('model','controller','view','api','mobile'))) return false;
155
		if(in_array($parent_module, array('module','addon','widget','layout'))) return false;
156
157
		$cache_file = './files/config/module_extend.php';
158
		FileHandler::removeFile($cache_file);
159
160
		$args = new stdClass;
161
		$args->parent_module = $parent_module;
162
		$args->extend_module = $extend_module;
163
		$args->type = $type;
164
		$args->kind = $kind;
165
166
		$output = executeQuery('module.getModuleExtendCount', $args);
167
		if($output->data->count>0) return false;
168
169
		$output = executeQuery('module.insertModuleExtend', $args);
170
		return $output;
171
	}
172
173
	/**
174
	 * @brief Delete module extend
175
	 *
176
	 */
177
	function deleteModuleExtend($parent_module, $extend_module, $type, $kind='')
178
	{
179
		$cache_file = './files/config/module_extend.php';
180
		FileHandler::removeFile($cache_file);
181
182
		$args = new stdClass;
183
		$args->parent_module = $parent_module;
184
		$args->extend_module = $extend_module;
185
		$args->type = $type;
186
		$args->kind = $kind;
187
188
		$output = executeQuery('module.deleteModuleExtend', $args);
189
190
		return $output;
191
	}
192
193
	function updateModuleConfig($module, $config, $site_srl = 0)
194
	{
195
		$args = new stdClass();
196
		$args->module = $module;
197
		$args->site_srl = $site_srl;
198
199
		$oModuleModel = getModel('module');
200
		$origin_config = $oModuleModel->getModuleConfig($module, $site_srl);
201
202
		if(!$origin_config) $origin_config = new stdClass;
203
204
		foreach($config as $key => $val)
205
		{
206
			$origin_config->{$key} = $val;
207
		}
208
209
		return $this->insertModuleConfig($module, $origin_config, $site_srl);
210
	}
211
212
	/**
213
	 * @brief Enter a specific set of modules
214
	 * In order to manage global configurations of modules such as board, member and so on
215
	 */
216 View Code Duplication
	function insertModuleConfig($module, $config, $site_srl = 0)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
217
	{
218
		$args =new stdClass();
219
		$args->module = $module;
220
		$args->config = serialize($config);
221
		$args->site_srl = $site_srl;
222
223
		$output = executeQuery('module.deleteModuleConfig', $args);
224
		if(!$output->toBool()) return $output;
225
226
		$output = executeQuery('module.insertModuleConfig', $args);
227
228
		//remove from cache
229
		$oCacheHandler = CacheHandler::getInstance('object', NULL, TRUE);
230
		if($oCacheHandler->isSupport())
231
		{
232
			$oCacheHandler->invalidateGroupKey('site_and_module');
233
		}
234
		return $output;
235
	}
236
237
	/**
238
	 * @brief Save module configurations of the mid
239
	 * Manage mid configurations depending on module
240
	 */
241 View Code Duplication
	function insertModulePartConfig($module, $module_srl, $config)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
242
	{
243
		$args = new stdClass();
244
		$args->module = $module;
245
		$args->module_srl = $module_srl;
246
		$args->config = serialize($config);
247
248
		$output = executeQuery('module.deleteModulePartConfig', $args);
249
		if(!$output->toBool()) return $output;
250
251
		$output = executeQuery('module.insertModulePartConfig', $args);
252
253
		//remove from cache
254
		$oCacheHandler = CacheHandler::getInstance('object', NULL, TRUE);
255
		if($oCacheHandler->isSupport())
256
		{
257
			$oCacheHandler->invalidateGroupKey('site_and_module');
258
		}
259
260
		return $output;
261
	}
262
263
	/**
264
	 * @brief create virtual site
265
	 */
266
	function insertSite($domain, $index_module_srl)
267
	{
268
		if(isSiteID($domain))
269
		{
270
			$oModuleModel = getModel('module');
271
			if($oModuleModel->isIDExists($domain, 0)) return new Object(-1,'msg_already_registed_vid');
272
		}
273
		else
274
		{
275
			$domain = strtolower($domain);
276
		}
277
278
		$args = new stdClass;
279
		$args->site_srl = getNextSequence();
280
		$args->domain = (substr_compare($domain, '/', -1) === 0) ? substr($domain, 0, -1) : $domain;
281
		$args->index_module_srl = $index_module_srl;
282
		$args->default_language = Context::getLangType();
283
284
		$columnList = array('modules.site_srl');
285
		$oModuleModel = getModel('module');
286
		$output = $oModuleModel->getSiteInfoByDomain($args->domain, $columnList);
287
		if($output) return new Object(-1,'msg_already_registed_vid');
288
289
		$output = executeQuery('module.insertSite', $args);
290
		if(!$output->toBool()) return $output;
291
292
		$output->add('site_srl', $args->site_srl);
293
		return $output;
294
	}
295
296
	/**
297
	 * @brief modify virtual site
298
	 */
299
	function updateSite($args)
300
	{
301
		$oModuleModel = getModel('module');
302
		$columnList = array('sites.site_srl', 'sites.domain');
303
		$site_info = $oModuleModel->getSiteInfo($args->site_srl, $columnList);
304
305
		if(!$args->domain && $site_info->site_srl == $args->site_srl)
306
		{
307
			$args->domain = $site_info->domain;
308
		}
309
310
		if($site_info->domain != $args->domain)
311
		{
312
			$info = $oModuleModel->getSiteInfoByDomain($args->domain, $columnList);
313
			if($info->site_srl && $info->site_srl != $args->site_srl) return new Object(-1,'msg_already_registed_domain');
314
			if(isSiteID($args->domain) && $oModuleModel->isIDExists($args->domain)) return new Object(-1,'msg_already_registed_vid');
315
316
			if($args->domain && !isSiteID($args->domain))
317
			{
318
				$args->domain = (strlen($args->domain) >= 1 && substr_compare($args->domain, '/', -1) === 0) ? substr($args->domain, 0, -1) : $args->domain;
319
			}
320
		}
321
		$output = executeQuery('module.updateSite', $args);
322
		//clear cache for default mid
323
		if($args->site_srl == 0) $vid='';
0 ignored issues
show
Unused Code introduced by
$vid is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
324
		else $vid=$args->domain;
0 ignored issues
show
Unused Code introduced by
$vid is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
325
326
		$module_info = $oModuleModel->getModuleInfoByModuleSrl($args->index_module_srl);
327
		$mid = $module_info->mid;
0 ignored issues
show
Unused Code introduced by
$mid is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
328
329
		$oCacheHandler = CacheHandler::getInstance('object', null, true);
330
		if($oCacheHandler->isSupport())
331
		{
332
			$oCacheHandler->invalidateGroupKey('site_and_module');
333
		}
334
335
		return $output;
336
	}
337
338
	/**
339
	 * @brief Arrange module information
340
	 */
341
	function arrangeModuleInfo(&$args, &$extra_vars)
342
	{
343
		// Remove unnecessary information
344
		unset($args->body);
345
		unset($args->act);
346
		unset($args->page);
347
		// Test mid value
348
		if(!preg_match("/^[a-z][a-z0-9_]+$/i", $args->mid)) return new Object(-1, 'msg_limit_mid');
349
		// Test variables (separate basic vars and other vars in modules)
350
		$extra_vars = clone($args);
351
		unset($extra_vars->module_srl);
352
		unset($extra_vars->module);
353
		unset($extra_vars->module_category_srl);
354
		unset($extra_vars->layout_srl);
355
		unset($extra_vars->mlayout_srl);
356
		unset($extra_vars->use_mobile);
357
		unset($extra_vars->menu_srl);
358
		unset($extra_vars->site_srl);
359
		unset($extra_vars->mid);
360
		unset($extra_vars->is_skin_fix);
361
		unset($extra_vars->skin);
362
		unset($extra_vars->is_mskin_fix);
363
		unset($extra_vars->mskin);
364
		unset($extra_vars->browser_title);
365
		unset($extra_vars->description);
366
		unset($extra_vars->is_default);
367
		unset($extra_vars->content);
368
		unset($extra_vars->mcontent);
369
		unset($extra_vars->open_rss);
370
		unset($extra_vars->header_text);
371
		unset($extra_vars->footer_text);
372
		$args = delObjectVars($args, $extra_vars);
373
374
		return new Object();
375
	}
376
377
	/**
378
	 * @brief Insert module
379
	 */
380
	function insertModule($args)
381
	{
382
		if(isset($args->isMenuCreate))
383
		{
384
			$isMenuCreate = $args->isMenuCreate;
385
		}
386
		else
387
		{
388
			$isMenuCreate = TRUE;
389
		}
390
391
		$output = $this->arrangeModuleInfo($args, $extra_vars);
392
		if(!$output->toBool()) return $output;
393
		// Check whether the module name already exists
394
		if(!$args->site_srl) $args->site_srl = 0;
395
		$oModuleModel = getModel('module');
396
		if($oModuleModel->isIDExists($args->mid, $args->site_srl)) return new Object(-1, 'msg_module_name_exists');
397
398
		// begin transaction
399
		$oDB = &DB::getInstance();
400
		$oDB->begin();
401
		// Get colorset from the skin information
402
		$module_path = ModuleHandler::getModulePath($args->module);
403
		$skin_info = $oModuleModel->loadSkinInfo($module_path, $args->skin);
404
		$skin_vars = new stdClass();
405
		$skin_vars->colorset = $skin_info->colorset[0]->name;
406
		// Arrange variables and then execute a query
407
		if(!$args->module_srl) $args->module_srl = getNextSequence();
408
409
		// default value
410 View Code Duplication
		if($args->skin == '/USE_DEFAULT/')
411
		{
412
			$args->is_skin_fix = 'N';
413
		}
414
		else
415
		{
416
			if(isset($args->is_skin_fix))
417
			{
418
				$args->is_skin_fix = ($args->is_skin_fix != 'Y') ? 'N' : 'Y';
419
			}
420
			else
421
			{
422
				$args->is_skin_fix = 'Y';
423
			}
424
		}
425
426 View Code Duplication
		if($args->mskin == '/USE_DEFAULT/')
427
		{
428
			$args->is_mskin_fix = 'N';
429
		}
430
		else
431
		{
432
			if(isset($args->is_mskin_fix))
433
			{
434
				$args->is_mskin_fix = ($args->is_mskin_fix != 'Y') ? 'N' : 'Y';
435
			}
436
			else
437
			{
438
				$args->is_mskin_fix = 'Y';
439
			}
440
		}
441
442
		unset($output);
443
444
		$args->browser_title = strip_tags($args->browser_title);
445
446
		if($isMenuCreate == TRUE)
447
		{
448
			$menuArgs = new stdClass;
449
			$menuArgs->menu_srl = $args->menu_srl;
450
			$menuOutput = executeQuery('menu.getMenu', $menuArgs);
451
452
			// if menu is not created, create menu also. and does not supported that in virtual site.
453
			if(!$menuOutput->data && !$args->site_srl)
454
			{
455
				$oMenuAdminModel = getAdminModel('menu');
0 ignored issues
show
Unused Code introduced by
$oMenuAdminModel is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
456
457
				$oMenuAdminController = getAdminController('menu');
458
				$menuSrl = $oMenuAdminController->getUnlinkedMenu();
459
460
				$menuArgs->menu_srl = $menuSrl;
461
				$menuArgs->menu_item_srl = getNextSequence();
462
				$menuArgs->parent_srl = 0;
463
				$menuArgs->open_window = 'N';
464
				$menuArgs->url = $args->mid;
465
				$menuArgs->expand = 'N';
466
				$menuArgs->is_shortcut = 'N';
467
				$menuArgs->name = $args->browser_title;
468
				$menuArgs->listorder = $args->menu_item_srl * -1;
469
470
				$menuItemOutput = executeQuery('menu.insertMenuItem', $menuArgs);
471
				if(!$menuItemOutput->toBool())
472
				{
473
					$oDB->rollback();
474
					return $menuItemOutput;
475
				}
476
477
				$oMenuAdminController->makeXmlFile($menuSrl);
478
			}
479
		}
480
481
		// Insert a module
482
		$args->menu_srl = $menuArgs->menu_srl;
0 ignored issues
show
Bug introduced by
The variable $menuArgs does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
483
		$output = executeQuery('module.insertModule', $args);
484
		if(!$output->toBool())
485
		{
486
			$oDB->rollback();
487
			return $output;
488
		}
489
		// Insert module extra vars
490
		$this->insertModuleExtraVars($args->module_srl, $extra_vars);
491
492
		// commit
493
		$oDB->commit();
494
495
		$oCacheHandler = CacheHandler::getInstance('object', null, true);
496
		if($oCacheHandler->isSupport())
497
		{
498
			$oCacheHandler->invalidateGroupKey('site_and_module');
499
		}
500
501
		$output->add('module_srl',$args->module_srl);
502
		return $output;
503
	}
504
505
	/**
506
	 * @brief Modify module information
507
	 */
508
	function updateModule($args)
509
	{
510
		$output = $this->arrangeModuleInfo($args, $extra_vars);
511
		if(!$output->toBool()) return $output;
512
		// begin transaction
513
		$oDB = &DB::getInstance();
514
		$oDB->begin();
515
516
		$oModuleModel = getModel('module');
517
		$columnList = array('module_srl', 'site_srl', 'browser_title', 'mid');
0 ignored issues
show
Unused Code introduced by
$columnList is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
518
		$module_info = $oModuleModel->getModuleInfoByModuleSrl($args->module_srl);
519
520
		if(!$args->site_srl || !$args->browser_title)
521
		{
522
			if(!$args->site_srl) $args->site_srl = (int)$module_info->site_srl;
523
			if(!$args->browser_title) $args->browser_title = $module_info->browser_title;
524
		}
525
526
		$args->browser_title = strip_tags($args->browser_title);
527
528
		$output = executeQuery('module.isExistsModuleName', $args);
529
		if(!$output->toBool() || $output->data->count)
530
		{
531
			$oDB->rollback();
532
			return new Object(-1, 'msg_module_name_exists');
533
		}
534
535
		// default value
536 View Code Duplication
		if($args->skin == '/USE_DEFAULT/')
537
		{
538
			$args->is_skin_fix = 'N';
539
		}
540
		else
541
		{
542
			if(isset($args->is_skin_fix))
543
			{
544
				$args->is_skin_fix = ($args->is_skin_fix != 'Y') ? 'N' : 'Y';
545
			}
546
			else
547
			{
548
				$args->is_skin_fix = 'Y';
549
			}
550
		}
551
552 View Code Duplication
		if($args->mskin == '/USE_DEFAULT/')
553
		{
554
			$args->is_mskin_fix = 'N';
555
		}
556
		else
557
		{
558
			if(isset($args->is_mskin_fix))
559
			{
560
				$args->is_mskin_fix = ($args->is_mskin_fix != 'Y') ? 'N' : 'Y';
561
			}
562
			else
563
			{
564
				$args->is_mskin_fix = 'Y';
565
			}
566
		}
567
		$output = executeQuery('module.updateModule', $args);
568
		if(!$output->toBool())
569
		{
570
			$oDB->rollback();
571
			return $output;
572
		}
573
574
		$menuArgs = new stdClass;
575
		$menuArgs->url = $module_info->mid;
576
		$menuArgs->site_srl = $module_info->site_srl;
577
		$menuOutput = executeQueryArray('menu.getMenuItemByUrl', $menuArgs);
578
		if($menuOutput->data && count($menuOutput->data))
579
		{
580
			$oMenuAdminController = getAdminController('menu');
581
			foreach($menuOutput->data as $itemInfo)
582
			{
583
				$itemInfo->url = $args->mid;
584
585
				$updateMenuItemOutput = $oMenuAdminController->updateMenuItem($itemInfo);
586
				if(!$updateMenuItemOutput->toBool())
587
				{
588
					$oDB->rollback();
589
					return $updateMenuItemOutput;
590
				}
591
			}
592
		}
593
594
		// if mid changed, change mid of success_return_url to new mid
595
		if($module_info->mid != $args->mid && Context::get('success_return_url'))
596
		{
597
			changeValueInUrl('mid', $args->mid, $module_info->mid);
598
		}
599
600
		// Insert module extra vars
601
		$this->insertModuleExtraVars($args->module_srl, $extra_vars);
602
603
		$oDB->commit();
604
605
		$output->add('module_srl',$args->module_srl);
606
607
		//remove from cache
608
		$oCacheHandler = CacheHandler::getInstance('object', null, true);
609
		if($oCacheHandler->isSupport())
610
		{
611
			$oCacheHandler->invalidateGroupKey('site_and_module');
612
		}
613
614
		return $output;
615
	}
616
617
	/**
618
	 * @brief 업데이트 기록 저장
619
	 * @param string $update_id
620
	 * @return Boolean
621
	 */
622
	public function insertUpdatedLog($update_id)
623
	{
624
		$args = new stdClass();
625
		$args->update_id = $update_id;
626
		$output = executeQuery('module.insertModuleUpdateLog', $args);
627
628
		if(!!$output->error) return false;
629
630
		return true;
631
	}
632
633
	/**
634
	 * @brief Change the module's virtual site
635
	 */
636
	function updateModuleSite($module_srl, $site_srl, $layout_srl = 0)
637
	{
638
		$args = new stdClass;
639
		$args->module_srl = $module_srl;
640
		$args->site_srl = $site_srl;
641
		$args->layout_srl = $layout_srl;
642
		$output = executeQuery('module.updateModuleSite', $args);
643
		if(!$output->toBool()) return $output;
644
645
		//remove from cache
646
		$oCacheHandler = CacheHandler::getInstance('object', null, true);
647
		if($oCacheHandler->isSupport())
648
		{
649
			$oCacheHandler->invalidateGroupKey('site_and_module');
650
		}
651
652
		return $output;
653
	}
654
655
	/**
656
	 * Delete module
657
	 * Attempt to delete all related information when deleting a module.
658
	 * Origin method is changed. because menu validation check is needed
659
	 */
660
	function deleteModule($module_srl, $site_srl = 0)
661
	{
662
		if(!$module_srl) return new Object(-1,'msg_invalid_request');
663
664
		$site_module_info = Context::get('site_module_info');
665
666
		$oModuleModel = getModel('module');
667
		$output = $oModuleModel->getModuleInfoByModuleSrl($module_srl);
668
669
		$args = new stdClass();
670
		$args->url = $output->mid;
671
		$args->is_shortcut = 'N';
672
		if(!$site_srl) $args->site_srl = $site_module_info->site_srl;
673
		else $args->site_srl = $site_srl;
674
675
		unset($output);
676
677
		$oMenuAdminModel = getAdminModel('menu');
678
		$menuOutput = $oMenuAdminModel->getMenuList($args);
679
680
		// get menu_srl by site_srl
681
		if(is_array($menuOutput->data))
682
		{
683
			foreach($menuOutput->data AS $key=>$value)
684
			{
685
				$args->menu_srl = $value->menu_srl;
686
				break;
687
			}
688
		}
689
690
		$output = executeQuery('menu.getMenuItemByUrl', $args);
691
		// menu delete
692
		if($output->data)
693
		{
694
			unset($args);
695
			$args = new stdClass;
696
			$args->menu_srl = $output->data->menu_srl;
697
			$args->menu_item_srl = $output->data->menu_item_srl;
698
			$args->is_force = 'N';
699
700
			$oMenuAdminController = getAdminController('menu');
701
			$output = $oMenuAdminController->deleteItem($args);
702
703
			if($output->isSuccess)
704
			{
705
				return new Object(0, 'success_deleted');
706
			}
707
			else
708
			{
709
				return new Object($output->error, $output->message);
710
			}
711
		}
712
		// only delete module
713
		else
714
		{
715
			return $this->onlyDeleteModule($module_srl);
716
		}
717
	}
718
719
	/**
720
	 * Delete module
721
	 * Attempt to delete all related information when deleting a module.
722
	 */
723
	public function onlyDeleteModule($module_srl)
724
	{
725
		if(!$module_srl) return new Object(-1,'msg_invalid_request');
726
727
		// check start module
728
		$oModuleModel = getModel('module');
729
		$columnList = array('sites.index_module_srl');
730
		$start_module = $oModuleModel->getSiteInfo(0, $columnList);
731
		if($module_srl == $start_module->index_module_srl) return new Object(-1, 'msg_cannot_delete_startmodule');
732
733
		// Call a trigger (before)
734
		$trigger_obj = new stdClass();
735
		$trigger_obj->module_srl = $module_srl;
736
		$output = ModuleHandler::triggerCall('module.deleteModule', 'before', $trigger_obj);
737
		if(!$output->toBool()) return $output;
738
739
		// begin transaction
740
		$oDB = &DB::getInstance();
741
		$oDB->begin();
742
743
		$args = new stdClass();
744
		$args->module_srl = $module_srl;
745
		// Delete module information from the DB
746
		$output = executeQuery('module.deleteModule', $args);
747
		if(!$output->toBool())
748
		{
749
			$oDB->rollback();
750
			return $output;
751
		}
752
		// Delete permission information
753
		$this->deleteModuleGrants($module_srl);
754
		// Remove skin information
755
		$this->deleteModuleSkinVars($module_srl);
756
		// Delete module extra vars
757
		$this->deleteModuleExtraVars($module_srl);
758
		// Remove the module manager
759
		$this->deleteAdminId($module_srl);
760
		// Call a trigger (after)
761 View Code Duplication
		if($output->toBool())
762
		{
763
			$trigger_output = ModuleHandler::triggerCall('module.deleteModule', 'after', $trigger_obj);
764
			if(!$trigger_output->toBool())
765
			{
766
				$oDB->rollback();
767
				return $trigger_output;
768
			}
769
		}
770
771
		// commit
772
		$oDB->commit();
773
774
		//remove from cache
775
		$oCacheHandler = CacheHandler::getInstance('object', null, true);
776
		if($oCacheHandler->isSupport())
777
		{
778
			$oCacheHandler->invalidateGroupKey('site_and_module');
779
		}
780
		return $output;
781
	}
782
783
	/**
784
	 * @brief Change other information of the module
785
	 * @deprecated
786
	 */
787
	function updateModuleSkinVars($module_srl, $skin_vars)
0 ignored issues
show
Unused Code introduced by
The parameter $module_srl is not used and could be removed.

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

Loading history...
Unused Code introduced by
The parameter $skin_vars is not used and could be removed.

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

Loading history...
788
	{
789
		return new Object();
790
	}
791
792
	/**
793
	 * @brief Set is_default as N in all modules(the default module is disabled)
794
	 */
795 View Code Duplication
	function clearDefaultModule()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
796
	{
797
		$output = executeQuery('module.clearDefaultModule');
798
		if(!$output->toBool()) return $output;
799
800
		$oCacheHandler = CacheHandler::getInstance('object', null, true);
801
		if($oCacheHandler->isSupport())
802
		{
803
			$oCacheHandler->invalidateGroupKey('site_and_module');
804
		}
805
806
		return $output;
807
	}
808
809
	/**
810
	 * @brief Update menu_srl of mid which belongs to menu_srl
811
	 */
812 View Code Duplication
	function updateModuleMenu($args)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
813
	{
814
		$output = executeQuery('module.updateModuleMenu', $args);
815
816
		$oCacheHandler = CacheHandler::getInstance('object', null, true);
817
		if($oCacheHandler->isSupport())
818
		{
819
			$oCacheHandler->invalidateGroupKey('site_and_module');
820
		}
821
822
		return $output;
823
	}
824
825
	/**
826
	 * @brief Update layout_srl of mid which belongs to menu_srl
827
	 */
828
	function updateModuleLayout($layout_srl, $menu_srl_list)
829
	{
830
		if(!count($menu_srl_list)) return;
831
832
		$args = new stdClass;
833
		$args->layout_srl = $layout_srl;
834
		$args->menu_srls = implode(',',$menu_srl_list);
835
		$output = executeQuery('module.updateModuleLayout', $args);
836
837
		$oCacheHandler = CacheHandler::getInstance('object', null, true);
838
		if($oCacheHandler->isSupport())
839
		{
840
			$oCacheHandler->invalidateGroupKey('site_and_module');
841
		}
842
843
		return $output;
844
	}
845
846
	/**
847
	 * @brief Change the site administrator
848
	 */
849
	function insertSiteAdmin($site_srl, $arr_admins)
850
	{
851
		// Remove the site administrator
852
		$args = new stdClass;
853
		$args->site_srl = $site_srl;
854
855
		$output = executeQuery('module.deleteSiteAdmin', $args);
856
857
		if(!$output->toBool()) return $output;
858
		// Get user id of an administrator
859
		if(!is_array($arr_admins) || !count($arr_admins)) return new Object();
860
		foreach($arr_admins as $key => $user_id)
861
		{
862
			if(!trim($user_id)) continue;
863
			$admins[] = trim($user_id);
0 ignored issues
show
Coding Style Comprehensibility introduced by
$admins was never initialized. Although not strictly required by PHP, it is generally a good practice to add $admins = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
864
		}
865
		if(!count($admins)) return new Object();
0 ignored issues
show
Bug introduced by
The variable $admins does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
866
867
		$oMemberModel = getModel('member');
868
		$member_config = $oMemberModel->getMemberConfig();
869
		if($member_config->identifier == 'email_address')
870
		{
871
			$args->email_address = '\''.implode('\',\'',$admins).'\'';
872
		}
873
		else
874
		{
875
			$args->user_ids = '\''.implode('\',\'',$admins).'\'';
876
		}
877
		$output = executeQueryArray('module.getAdminSrls', $args);
878
		if(!$output->toBool()||!$output->data) return $output;
879
880
		foreach($output->data as $key => $val)
881
		{
882
			unset($args);
883
			$args = new stdClass;
884
			$args->site_srl = $site_srl;
885
			$args->member_srl = $val->member_srl;
886
			$output = executeQueryArray('module.insertSiteAdmin', $args);
887
			if(!$output->toBool()) return $output;
888
		}
889
		return new Object();
890
	}
891
892
	/**
893
	 * @brief Specify the admin ID to a module
894
	 */
895
	function insertAdminId($module_srl, $admin_id)
896
	{
897
		$oMemberModel = getModel('member');
898
		$member_config = $oMemberModel->getMemberConfig();
899
900
		if($member_config->identifier == 'email_address')
901
			$member_info = $oMemberModel->getMemberInfoByEmailAddress($admin_id);
902
		else
903
			$member_info = $oMemberModel->getMemberInfoByUserID($admin_id);
904
905
		if(!$member_info->member_srl) return;
906
		$args = new stdClass();
907
		$args->module_srl = $module_srl;
908
		$args->member_srl = $member_info->member_srl;
909
		return executeQuery('module.insertAdminId', $args);
910
	}
911
912
	/**
913
	 * @brief Remove the admin ID from a module
914
	 */
915
	function deleteAdminId($module_srl, $admin_id = '')
916
	{
917
		$args = new stdClass();
918
		$args->module_srl = $module_srl;
919
920
		if($admin_id)
921
		{
922
			$oMemberModel = getModel('member');
923
			$member_info = $oMemberModel->getMemberInfoByUserID($admin_id);
924
			if($member_info->member_srl) $args->member_srl = $member_info->member_srl;
925
		}
926
		return executeQuery('module.deleteAdminId', $args);
927
	}
928
929
	/**
930
	 * Insert skin vars to a module
931
	 * @param $module_srl Sequence of module
932
	 * @param $obj Skin variables
933
	 */
934
	function insertModuleSkinVars($module_srl, $obj)
935
	{
936
		return $this->_insertModuleSkinVars($module_srl, $obj, 'P');
937
	}
938
939
	/**
940
	 * Insert mobile skin vars to a module
941
	 * @param $module_srl Sequence of module
942
	 * @param $obj Skin variables
943
	 */
944
	function insertModuleMobileSkinVars($module_srl, $obj)
945
	{
946
		return $this->_insertModuleSkinVars($module_srl, $obj, 'M');
947
	}
948
949
950
	/**
951
	 * @brief Insert skin vars to a module
952
	 */
953
	function _insertModuleSkinVars($module_srl, $obj, $mode)
954
	{
955
		$mode = $mode === 'P' ? 'P' : 'M';
956
957
		$oDB = DB::getInstance();
958
		$oDB->begin();
959
960
		$output = $this->_deleteModuleSkinVars($module_srl, $mode);
961
		if(!$output->toBool())
962
		{
963
			$oDB->rollback();
964
			return $output;
965
		}
966
967
		getDestroyXeVars($obj);
968
		if(!$obj || !count($obj)) return new Object();
969
970
		$args = new stdClass;
971
		$args->module_srl = $module_srl;
972
		foreach($obj as $key => $val)
973
		{
974
			// #17927989 For an old board which used the old blog module
975
			// it often saved menu item(stdClass) on the skin info column
976
			// When updating the module on XE core 1.2.0 later versions, it occurs an error
977
			// fixed the error
978
			if (is_object($val)) continue;
979
			if (is_array($val)) $val = serialize($val);
980
981
			$args->name = trim($key);
982
			$args->value = trim($val);
983
			if(!$args->name || !$args->value) continue;
984
985
			if($mode === 'P')
986
			{
987
				$output = executeQuery('module.insertModuleSkinVars', $args);
988
			}
989
			else
990
			{
991
				$output = executeQuery('module.insertModuleMobileSkinVars', $args);
992
			}
993
			if(!$output->toBool())
994
			{
995
				return $output;
996
				$oDB->rollback();
0 ignored issues
show
Unused Code introduced by
$oDB->rollback(); does not seem to be 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...
997
			}
998
		}
999
1000
		$oDB->commit();
1001
1002
		return new Object();
1003
	}
1004
1005
	/**
1006
	 * Remove skin vars ofa module
1007
	 * @param $module_srl seqence of module
1008
	 */
1009
	function deleteModuleSkinVars($module_srl)
1010
	{
1011
		return $this->_deleteModuleSkinVars($module_srl, 'P');
1012
	}
1013
1014
	/**
1015
	 * Remove mobile skin vars ofa module
1016
	 * @param $module_srl seqence of module
1017
	 */
1018
	function deleteModuleMobileSkinVars($module_srl)
1019
	{
1020
		return $this->_deleteModuleSkinVars($module_srl, 'M');
1021
	}
1022
1023
	/**
1024
	 * @brief Remove skin vars of a module
1025
	 */
1026
	function _deleteModuleSkinVars($module_srl, $mode)
1027
	{
1028
		$args = new stdClass();
1029
		$args->module_srl = $module_srl;
1030
		$mode = $mode === 'P' ? 'P' : 'M';
1031
1032
		if($mode === 'P')
1033
		{
1034
			$object_key = 'module_skin_vars:'.$module_srl;
1035
			$query = 'module.deleteModuleSkinVars';
1036
		}
1037
		else
1038
		{
1039
			$object_key = 'module_mobile_skin_vars:'.$module_srl;
1040
			$query = 'module.deleteModuleMobileSkinVars';
1041
		}
1042
1043
		//remove from cache
1044
		$oCacheHandler = CacheHandler::getInstance('object', null, true);
1045
		$cache_key = $oCacheHandler->getGroupKey('site_and_module', $object_key);
1046
		if($oCacheHandler->isSupport())
1047
		{
1048
			$oCacheHandler->delete($cache_key);
1049
		}
1050
1051
		return executeQuery($query, $args);
1052
	}
1053
1054
	/**
1055
	 * @brief Register extra vars to the module
1056
	 */
1057
	function insertModuleExtraVars($module_srl, $obj)
1058
	{
1059
		$this->deleteModuleExtraVars($module_srl);
1060
		getDestroyXeVars($obj);
1061
		if(!$obj || !count($obj)) return;
1062
1063
		foreach($obj as $key => $val)
1064
		{
1065
			if(is_object($val) || is_array($val)) continue;
1066
1067
			$args = new stdClass();
1068
			$args->module_srl = $module_srl;
1069
			$args->name = trim($key);
1070
			$args->value = trim($val);
1071
			if(!$args->name || !$args->value) continue;
1072
			$output = executeQuery('module.insertModuleExtraVars', $args);
0 ignored issues
show
Unused Code introduced by
$output is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
1073
		}
1074
1075
		$oCacheHandler = CacheHandler::getInstance('object', null, true);
1076
		if($oCacheHandler->isSupport())
1077
		{
1078
			$object_key = 'module_extra_vars:'.$module_srl;
1079
			$cache_key = $oCacheHandler->getGroupKey('site_and_module', $object_key);
1080
			$oCacheHandler->delete($cache_key);
1081
		}
1082
	}
1083
1084
	/**
1085
	 * @brief Remove extra vars from the module
1086
	 */
1087 View Code Duplication
	function deleteModuleExtraVars($module_srl)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1088
	{
1089
		$args = new stdClass();
1090
		$args->module_srl = $module_srl;
1091
		$output = executeQuery('module.deleteModuleExtraVars', $args);
1092
1093
		//remove from cache
1094
		$oCacheHandler = CacheHandler::getInstance('object', null, true);
1095
		if($oCacheHandler->isSupport())
1096
		{
1097
			$object_key = 'module_extra_vars:'.$module_srl;
1098
			$cache_key = $oCacheHandler->getGroupKey('site_and_module', $object_key);
1099
			$oCacheHandler->delete($cache_key);
1100
		}
1101
1102
		return $output;
1103
	}
1104
1105
	/**
1106
	 * @brief Grant permission to the module
1107
	 */
1108
	function insertModuleGrants($module_srl, $obj)
1109
	{
1110
		$this->deleteModuleGrants($module_srl);
1111
		if(!$obj || !count($obj)) return;
1112
1113
		foreach($obj as $name => $val)
1114
		{
1115
			if(!$val || !count($val)) continue;
1116
1117
			foreach($val as $group_srl)
1118
			{
1119
				$args = new stdClass();
1120
				$args->module_srl = $module_srl;
1121
				$args->name = $name;
1122
				$args->group_srl = trim($group_srl);
1123
				if(!$args->name || !$args->group_srl) continue;
1124
				executeQuery('module.insertModuleGrant', $args);
1125
			}
1126
		}
1127
	}
1128
1129
	/**
1130
	 * @brief Remove permission from the module
1131
	 */
1132
	function deleteModuleGrants($module_srl)
1133
	{
1134
		$args = new stdClass();
1135
		$args->module_srl = $module_srl;
1136
		return executeQuery('module.deleteModuleGrants', $args);
1137
	}
1138
1139
	/**
1140
	 * @brief Change user-defined language
1141
	 */
1142
	function replaceDefinedLangCode(&$output, $isReplaceLangCode = true)
1143
	{
1144
		if($isReplaceLangCode)
1145
		{
1146
			$output = preg_replace_callback('!\$user_lang->([a-z0-9\_]+)!is', array($this,'_replaceLangCode'), $output);
1147
		}
1148
	}
1149
1150
	function _replaceLangCode($matches)
1151
	{
1152
		static $lang = null;
1153
1154
		if(is_null($lang))
1155
		{
1156
			$site_module_info = Context::get('site_module_info');
1157
			if(!$site_module_info)
1158
			{
1159
				$oModuleModel = getModel('module');
1160
				$site_module_info = $oModuleModel->getDefaultMid();
1161
				Context::set('site_module_info', $site_module_info);
1162
			}
1163
			$cache_file = sprintf('%sfiles/cache/lang_defined/%d.%s.php', _XE_PATH_, $site_module_info->site_srl, Context::getLangType());
1164
			if(!file_exists($cache_file))
1165
			{
1166
				$oModuleAdminController = getAdminController('module');
1167
				$oModuleAdminController->makeCacheDefinedLangCode($site_module_info->site_srl);
1168
			}
1169
1170
			if(file_exists($cache_file))
1171
			{
1172
				$moduleAdminControllerMtime = filemtime(_XE_PATH_ . 'modules/module/module.admin.controller.php');
1173
				$cacheFileMtime = filemtime($cache_file);
1174
				if($cacheFileMtime < $moduleAdminControllerMtime)
1175
				{
1176
					$oModuleAdminController = getAdminController('module');
1177
					$oModuleAdminController->makeCacheDefinedLangCode($site_module_info->site_srl);
1178
				}
1179
1180
				require_once($cache_file);
1181
			}
1182
		}
1183
		if(!Context::get($matches[1]) && $lang[$matches[1]]) return $lang[$matches[1]];
1184
1185
		return str_replace('$user_lang->','',$matches[0]);
1186
	}
1187
1188
1189
	/**
1190
	 * @brief Add and update a file into the file box
1191
	 */
1192
	function procModuleFileBoxAdd()
1193
	{
1194
		$ajax = Context::get('ajax');
1195
		if ($ajax) Context::setRequestMethod('JSON');
1196
1197
		$logged_info = Context::get('logged_info');
1198
		if($logged_info->is_admin !='Y' && !$logged_info->is_site_admin) return new Object(-1, 'msg_not_permitted');
1199
1200
		$vars = Context::gets('addfile','filter');
1201
		$attributeNames = Context::get('attribute_name');
1202
		$attributeValues = Context::get('attribute_value');
1203
		if(is_array($attributeNames) && is_array($attributeValues) && count($attributeNames) == count($attributeValues))
1204
		{
1205
			$attributes = array();
1206
			foreach($attributeNames as $no => $name)
1207
			{
1208
				if(empty($name))
1209
				{
1210
					continue;
1211
				}
1212
				$attributes[] = sprintf('%s:%s', $name, $attributeValues[$no]);
1213
			}
1214
			$attributes = implode(';', $attributes);
1215
		}
1216
1217
		$vars->comment = $attributes;
0 ignored issues
show
Bug introduced by
The variable $attributes does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
1218
		$module_filebox_srl = Context::get('module_filebox_srl');
1219
1220
		$ext = strtolower(substr(strrchr($vars->addfile['name'],'.'),1));
1221
		$vars->ext = $ext;
1222
		if($vars->filter) $filter = explode(',',$vars->filter);
1223
		else $filter = array('jpg','jpeg','gif','png');
1224
		if(!in_array($ext,$filter)) return new Object(-1, 'msg_error_occured');
1225
1226
		$vars->member_srl = $logged_info->member_srl;
1227
1228
		// update
1229
		if($module_filebox_srl > 0)
1230
		{
1231
			$vars->module_filebox_srl = $module_filebox_srl;
1232
			$output = $this->updateModuleFileBox($vars);
1233
		}
1234
		// insert
1235
		else
1236
		{
1237
			if(!Context::isUploaded()) return new Object(-1, 'msg_error_occured');
1238
			$addfile = Context::get('addfile');
1239
			if(!is_uploaded_file($addfile['tmp_name'])) return new Object(-1, 'msg_error_occured');
1240
			if($vars->addfile['error'] != 0) return new Object(-1, 'msg_error_occured');
1241
			$output = $this->insertModuleFileBox($vars);
1242
		}
1243
1244
		$this->setTemplatePath($this->module_path.'tpl');
1245
1246
		if (!$ajax)
1247
		{
1248
			$returnUrl = Context::get('success_return_url') ? Context::get('success_return_url') : getNotEncodedUrl('', 'module', 'admin', 'act', 'dispModuleAdminFileBox');
1249
			$this->setRedirectUrl($returnUrl);
1250
			return;
1251
		}
1252
		else
1253
		{
1254
			if($output) $this->add('save_filename', $output->get('save_filename'));
1255
			else $this->add('save_filename', '');
1256
		}
1257
	}
1258
1259
	/**
1260
	 * @brief Update a file into the file box
1261
	 */
1262
	function updateModuleFileBox($vars)
1263
	{
1264
		$args = new stdClass;
1265
		// have file
1266
		if($vars->addfile['tmp_name'] && is_uploaded_file($vars->addfile['tmp_name']))
1267
		{
1268
			$oModuleModel = getModel('module');
1269
			$output = $oModuleModel->getModuleFileBox($vars->module_filebox_srl);
1270
			FileHandler::removeFile($output->data->filename);
1271
1272
			$path = $oModuleModel->getModuleFileBoxPath($vars->module_filebox_srl);
1273
			FileHandler::makeDir($path);
1274
1275
			$save_filename = sprintf('%s%s.%s',$path, $vars->module_filebox_srl, $ext);
0 ignored issues
show
Bug introduced by
The variable $ext does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
1276
			$tmp = $vars->addfile['tmp_name'];
1277
1278
			// Check uploaded file
1279
			if(!checkUploadedFile($tmp)) return false;
1280
1281
			if(!@move_uploaded_file($tmp, $save_filename))
1282
			{
1283
				return false;
1284
			}
1285
1286
			$args->fileextension = strtolower(substr(strrchr($vars->addfile['name'],'.'),1));
1287
			$args->filename = $save_filename;
1288
			$args->filesize = $vars->addfile['size'];
1289
		}
1290
1291
		$args->module_filebox_srl = $vars->module_filebox_srl;
1292
		$args->comment = $vars->comment;
1293
1294
		// FIXME $args ??
1295
1296
		return executeQuery('module.updateModuleFileBox', $vars);
1297
	}
1298
1299
1300
	/**
1301
	 * @brief Add a file into the file box
1302
	 */
1303
	function insertModuleFileBox($vars)
1304
	{
1305
		// set module_filebox_srl
1306
		$vars->module_filebox_srl = getNextSequence();
1307
1308
		// get file path
1309
		$oModuleModel = getModel('module');
1310
		$path = $oModuleModel->getModuleFileBoxPath($vars->module_filebox_srl);
1311
		FileHandler::makeDir($path);
1312
		$save_filename = sprintf('%s%s.%s',$path, $vars->module_filebox_srl, $vars->ext);
1313
		$tmp = $vars->addfile['tmp_name'];
1314
1315
		// Check uploaded file
1316
		if(!checkUploadedFile($tmp)) return false;
1317
1318
		// upload
1319
		if(!@move_uploaded_file($tmp, $save_filename))
1320
		{
1321
			return false;
1322
		}
1323
1324
		// insert
1325
		$args = new stdClass;
1326
		$args->module_filebox_srl = $vars->module_filebox_srl;
1327
		$args->member_srl = $vars->member_srl;
1328
		$args->comment = $vars->comment;
1329
		$args->filename = $save_filename;
1330
		$args->fileextension = strtolower(substr(strrchr($vars->addfile['name'],'.'),1));
1331
		$args->filesize = $vars->addfile['size'];
1332
1333
		$output = executeQuery('module.insertModuleFileBox', $args);
1334
		$output->add('save_filename', $save_filename);
1335
		return $output;
1336
	}
1337
1338
1339
	/**
1340
	 * @brief Delete a file from the file box
1341
	 */
1342
	function procModuleFileBoxDelete()
1343
	{
1344
		$logged_info = Context::get('logged_info');
1345
		if($logged_info->is_admin !='Y' && !$logged_info->is_site_admin) return new Object(-1, 'msg_not_permitted');
1346
1347
		$module_filebox_srl = Context::get('module_filebox_srl');
1348
		if(!$module_filebox_srl) return new Object(-1, 'msg_invalid_request');
1349
		$vars = new stdClass();
1350
		$vars->module_filebox_srl = $module_filebox_srl;
1351
		$output = $this->deleteModuleFileBox($vars);
1352
		if(!$output->toBool()) return $output;
1353
	}
1354
1355
	function deleteModuleFileBox($vars)
1356
	{
1357
		// delete real file
1358
		$oModuleModel = getModel('module');
1359
		$output = $oModuleModel->getModuleFileBox($vars->module_filebox_srl);
1360
		FileHandler::removeFile($output->data->filename);
1361
1362
		$args = new stdClass();
1363
		$args->module_filebox_srl = $vars->module_filebox_srl;
1364
		return executeQuery('module.deleteModuleFileBox', $args);
1365
	}
1366
1367
	/**
1368
	 * @brief function of locking (timeout is in seconds)
1369
	 */
1370
	function lock($lock_name, $timeout, $member_srl = null)
1371
	{
1372
		$this->unlockTimeoutPassed();
1373
		$args = new stdClass;
1374
		$args->lock_name = $lock_name;
1375
		if(!$timeout) $timeout = 60;
1376
		$args->deadline = date("YmdHis", $_SERVER['REQUEST_TIME'] + $timeout);
1377
		if($member_srl) $args->member_srl = $member_srl;
1378
		$output = executeQuery('module.insertLock', $args);
1379
		if($output->toBool())
1380
		{
1381
			$output->add('lock_name', $lock_name);
1382
			$output->add('deadline', $args->deadline);
1383
		}
1384
		return $output;
1385
	}
1386
1387
	function unlockTimeoutPassed()
1388
	{
1389
		executeQuery('module.deleteLocksTimeoutPassed');
1390
	}
1391
1392
	function unlock($lock_name, $deadline)
1393
	{
1394
		$args = new stdClass;
1395
		$args->lock_name = $lock_name;
1396
		$args->deadline = $deadline;
1397
		$output = executeQuery('module.deleteLock', $args);
1398
		return $output;
1399
	}
1400
1401
	function updateModuleInSites($site_srls, $args)
0 ignored issues
show
Unused Code introduced by
The parameter $args is not used and could be removed.

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

Loading history...
1402
	{
1403
		$args = new stdClass;
1404
		$args->site_srls = $site_srls;
1405
		$output = executeQuery('module.updateModuleInSites', $args);
1406
1407
		$oCacheHandler = CacheHandler::getInstance('object', null, true);
1408
		if($oCacheHandler->isSupport())
1409
		{
1410
			$oCacheHandler->invalidateGroupKey('site_and_module');
1411
		}
1412
1413
		return $output;
1414
	}
1415
}
1416
/* End of file module.controller.php */
1417
/* Location: ./modules/module/module.controller.php */
1418