updater/index.php
/**
	 * Delete old files from the system as much as possible
	 *
	 * @throws \Exception
	 */
Delete old files from the system as much as possible
@throws \Exception
Delete old files from the system as much as possible @throws \ Exception
public function deleteOldFiles() {
		$this->silentLog('[info] deleteOldFiles()');
		$shippedAppsFile = $this->baseDir . '/../core/shipped.json';
		if(!file_exists($shippedAppsFile)) {
			throw new \Exception('core/shipped.json is not available');
		}
		$shippedApps = json_decode(file_get_contents($shippedAppsFile), true);
		foreach($shippedApps['shippedApps'] as $app) {
			$this->recursiveDelete($this->baseDir . '/../apps/' . $app);
		}
		$configSampleFile = $this->baseDir . '/../config/config.sample.php';
		if(file_exists($configSampleFile)) {
			$this->silentLog('[info] config sample exists');
			$state = unlink($configSampleFile);
			if ($state === false) {
				throw new \Exception('Could not unlink sample config');
			}
		}
		$themesReadme = $this->baseDir . '/../themes/README';
		if(file_exists($themesReadme)) {
			$this->silentLog('[info] thmes README exists');
			$state = unlink($themesReadme);
			if ($state === false) {
				throw new \Exception('Could not delete themes README');
			}
		}
		$this->recursiveDelete($this->baseDir . '/../themes/example/');
		$excludedElements = [
			'data',
			'index.php',
			'status.php',
			'remote.php',
			'public.php',
			'ocs/v1.php',
			'ocs/v2.php',
			'config',
			'themes',
			'apps',
			'updater',
		];
		foreach ($this->getRecursiveDirectoryIterator() as $path => $fileInfo) {
			$currentDir = $this->baseDir . '/../';
			$fileName = explode($currentDir, $path)[1];
			$folderStructure = explode('/', $fileName, -1);
			if(isset($folderStructure[0])) {
				if(array_search($folderStructure[0], $excludedElements) !== false) {
					continue;
				}
			} else {
				if(array_search($fileName, $excludedElements) !== false) {
					continue;
				}
			}
			if($fileInfo->isFile()) {
				$state = unlink($path);
				if($state === false) {
					throw new \Exception('Could not unlink: '.$path);
				}
			} elseif($fileInfo->isDir()) {
				$state = rmdir($path);
				if($state === false) {
					throw new \Exception('Could not rmdir: '.$path);
				}
			}
		}
		$this->silentLog('[info] end of deleteOldFiles()');
	}
public function deleteOldFiles ( ) { $ this -> silentLog ( '[info] deleteOldFiles()' ) ; $ shippedAppsFile = $ this -> baseDir . '/../core/shipped.json' ; if ( ! file_exists ( $ shippedAppsFile ) ) { throw new \ Exception ( 'core/shipped.json is not available' ) ; } $ shippedApps = json_decode ( file_get_contents ( $ shippedAppsFile ) , true ) ; foreach ( $ shippedApps [ 'shippedApps' ] as $ app ) { $ this -> recursiveDelete ( $ this -> baseDir . '/../apps/' . $ app ) ; } $ configSampleFile = $ this -> baseDir . '/../config/config.sample.php' ; if ( file_exists ( $ configSampleFile ) ) { $ this -> silentLog ( '[info] config sample exists' ) ; $ state = unlink ( $ configSampleFile ) ; if ( $ state === false ) { throw new \ Exception ( 'Could not unlink sample config' ) ; } } $ themesReadme = $ this -> baseDir . '/../themes/README' ; if ( file_exists ( $ themesReadme ) ) { $ this -> silentLog ( '[info] thmes README exists' ) ; $ state = unlink ( $ themesReadme ) ; if ( $ state === false ) { throw new \ Exception ( 'Could not delete themes README' ) ; } } $ this -> recursiveDelete ( $ this -> baseDir . '/../themes/example/' ) ; $ excludedElements = [ 'data' , 'index.php' , 'status.php' , 'remote.php' , 'public.php' , 'ocs/v1.php' , 'ocs/v2.php' , 'config' , 'themes' , 'apps' , 'updater' , ] ; foreach ( $ this -> getRecursiveDirectoryIterator ( ) as $ path => $ fileInfo ) { $ currentDir = $ this -> baseDir . '/../' ; $ fileName = explode ( $ currentDir , $ path ) [ 1 ] ; $ folderStructure = explode ( '/' , $ fileName , - 1 ) ; if ( isset ( $ folderStructure [ 0 ] ) ) { if ( array_search ( $ folderStructure [ 0 ] , $ excludedElements ) !== false ) { continue ; } } else { if ( array_search ( $ fileName , $ excludedElements ) !== false ) { continue ; } } if ( $ fileInfo -> isFile ( ) ) { $ state = unlink ( $ path ) ; if ( $ state === false ) { throw new \ Exception ( 'Could not unlink: ' . $ path ) ; } } elseif ( $ fileInfo -> isDir ( ) ) { $ state = rmdir ( $ path ) ; if ( $ state === false ) { throw new \ Exception ( 'Could not rmdir: ' . $ path ) ; } } } $ this -> silentLog ( '[info] end of deleteOldFiles()' ) ; }
Delete old files from the system as much as possible
 @throws \Exception
Delete old files from the system as much as possible @throws \ Exception
// Delete shipped apps // Delete example config // Delete themes // Delete the rest /**
		 * @var string $path
		 * @var \SplFileInfo $fileInfo
		 */ // Exclude the exclusions