Completed
Push — ylebre-svn-fixes ( 2859de )
by
unknown
64:29
created

upgrade.files.php ➔ recurse()   C

Complexity

Conditions 14
Paths 60

Size

Total Lines 35

Duplication

Lines 3
Ratio 8.57 %

Importance

Changes 0
Metric Value
cc 14
nc 60
nop 1
dl 3
loc 35
rs 6.2666
c 0
b 0
f 0

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
	$code		= $store->get_config("code");
3
	$files = $store->get_config("files")."files/";
4
	$needsUpgrade = array();
5
6 View Code Duplication
	function pathToObjectID($path) {
0 ignored issues
show
Duplication introduced by
This function 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...
7
		global $files;
8
		$objectID = 0;
9
		$subpath = substr($path,strlen($files));
10
		$numbers = explode('/',$subpath);;
11
		while (count($numbers)){
12
			$pathicle = array_pop($numbers);
13
			$objectID = $objectID * 100;
14
			$objectID += (int)$pathicle;
15
		}
16
17
		return $objectID;
18
	}
19
20
	function parseFile($file) {
21
		preg_match('/^_((?<nls>[a-z]{2})_)?(?<file>.+)$/',$file,$matches);
22
		if( $matches['nls'] == '') {
23
			$matches['nls'] = 'none';
24
		}
25
		return $matches;
26
	}
27
28
	function recurse($path) {
29
		global $AR,$needsUpgrade;
30
		$dh = opendir($path);
31
		$files = array();
32
		$nlsFiles = array();
33
		$dirs = array();
34
		$objectID = pathToObjectID($path);
35
		while ( is_resource($dh) && false !== ($file = readdir($dh))) {
36
			if ($file != "." && $file != "..") {
37
				$f = $path.$file;
38
				if ( is_file($f) && $file[0] == '_' ) {
39
					$files[]=$file;
40 View Code Duplication
				} else if (is_dir($f) && $file != "CVS" && $file != ".svn") {
41
					$dirs[]=$f."/";
42
				}
43
			}
44
		}
45
		closedir($dh);
46
		foreach($files as $file){
47
			$info = parseFile($file);
48
			$nlsFiles[$info['file']][$info['nls']]  = $info;
49
		}
50
		unset($files);
51
		foreach($nlsFiles as $basefile => $nlsData) {
52
			if( count($nlsData)  ){
53
				$needsUpgrade[$objectID]=''.$objectID;
54
			}
55
		}
56
		unset($nlsFiles);
57
58
		foreach($dirs as $dir){
59
			recurse($dir);
60
		}
61
		unset($dirs);
62
	}
63
64
	recurse($files);
65
66
	sort($needsUpgrade);
67
68
	// in large instalations, the store mysql connction has timed out by now, restarting store
69
	global $store,$store_config;
70
	$inst_store = $store_config["dbms"]."store";
71
	$store=new $inst_store($root,$store_config);
72
73
74
	foreach($needsUpgrade as $objID) {
75
		print "Searching for $objID\n";
76
		$result = ar::get('/')->find("id == $objID")->call('system.get.phtml');
77
		if(count($result) == 1) {
78
			$obj = current($result);
79
			print "Upgrading ".$obj->path."\n<br>";
80
			$obj->call('system.upgrade.filestore.8.4.php');
81
		}
82
	}
83
84
	echo "Done with converting nls filestore.<br>\n";
85
?>
0 ignored issues
show
Best Practice introduced by
It is not recommended to use PHP's closing tag ?> in files other than templates.

Using a closing tag in PHP files that only contain PHP code is not recommended as you might accidentally add whitespace after the closing tag which would then be output by PHP. This can cause severe problems, for example headers cannot be sent anymore.

A simple precaution is to leave off the closing tag as it is not required, and it also has no negative effects whatsoever.

Loading history...