Blame view

sources/apps/updater/lib/location/core.php 1.93 KB
03e52840d   Kload   Init
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
  <?php
  
  /**
   * ownCloud - Updater plugin
   *
   * @author Victor Dubiniuk
   * @copyright 2013 Victor Dubiniuk victor.dubiniuk@gmail.com
   *
   * This file is licensed under the Affero General Public License version 3 or
   * later.
   */
  
  namespace OCA\Updater;
  
  class Location_Core extends Location {
  
  	protected $type = 'core';
  	
  	public function check() {
  		$errors = parent::check();
  		$specialCases = array(
  			$this->oldBase . '/' . 'config',
  			$this->oldBase . '/' . 'themes',
  		);
  
  		foreach ($specialCases as $item) {
  			if (!is_writable($item)) {
  				$errors[] = $item;
  			}
  		}
  
  		return $errors;
  	}
  
  	protected function filterOld($pathArray) {
  		$skip = array_values(Helper::getDirectories());
  		$skip[] = rtrim(App::getBackupBase(), '/');
  		$skip[] = \OC_Config::getValue("datadirectory", \OC::$SERVERROOT . "/data");
  
  		// Skip 3rdparty | apps | backup | datadir | config | themes
  		foreach ($pathArray as $key => $path) {
  			if ($path === 'config' || $path === 'themes') {
  				unset($pathArray[$key]);
  			}
  			if (in_array($this->oldBase . '/' . $path, $skip)) {
  				unset($pathArray[$key]);
  			}
  		}
  		return $pathArray;
  	}
  
  	protected function filterNew($pathArray) {
  		// Skip config | themes
  		foreach ($pathArray as $key => $path) {
  			if ($path === 'config' || $path === 'themes') {
  				unset($pathArray[$key]);
  			}
  		}
  		return $pathArray;
  	}
  
  	protected function finalize() {
  		// overwrite config.sample.php
  		Helper::removeIfExists($this->oldBase . '/config/config.sample.php');
  		Helper::move($this->newBase . '/config/config.sample.php', $this->oldBase . '/config/config.sample.php');
  
  		// overwrite themes content with new files only
  		$themes = $this->toAbsolute(
  				$this->newBase . '/themes', Helper::scandir($this->newBase . '/themes')
  		);
  
  		foreach ($themes as $name => $location) {
  			Helper::removeIfExists($this->oldBase . '/themes/' . $name);
  			Helper::move($location, $this->oldBase . '/themes/' . $name);
  		}
  
  		parent::finalize();
  	}
  
  }