public function actionInstall($name=false)
	{
		if ($name == false || defined('CII_CONFIG'))
			return false;

		$filePath 	= Yii::getPathOfAlias('base.themes').DS.$name;
		$details 	= $this->actionDetails($name);

		// If the theme is already installed, make sure it is the correct version, otherwise we'll be performing an upgrade
		if ($this->actionIsInstalled($name, true))
		{
			if (file_exists($filePath.DS.'VERSION'))
			{
				$version = file_get_contents($filePath.DS.'VERSION');

				if ($version == $details['latest-version'])
					return true;
			}
		}

		// Set several variables to store the various paths we'll need
		$tmpPath 	= Yii::getPathOfAlias('application.runtime.themes').DS.$name;
		$themesPath = Yii::getPathOfAlias('application.runtime').DS.'themes';
		$zipPath 	= $themesPath.DS.$details['sha'].'.zip';

		// Verify the temporary directory exists
		if (!file_exists($themesPath))
			mkdir($themesPath);

		// Download the ZIP package to the runtime/themes temporary directory
		
		if (!$this->downloadPackage($details['sha'], $details['file'], Yii::getPathOfAlias('application.runtime.themes')))
			throw new CHttpException(500, Yii::t('Api.theme', 'Failed to download theme package from Github. Source might be down'));

		$zip = new ZipArchive;

		// If we can open the file
		if ($zip->open($zipPath) === true)
		{
			// And we were able to extract it
			if ($zip->extractTo($themesPath.DS.$details['sha']))
			{
				// Close the ZIP connection
				$zip->close();

				// Delete the downloaded ZIP file
				unlink($zipPath);

				// Move the folders around so we're operating on the bare folder, then delete the teporary folder
				rename($themesPath.DS.$details['sha'].DS.'ciims-themes-'.$name.'-'.$details['latest-version'], $tmpPath);
				rmdir(str_replace('.zip', '', $zipPath));

				// Store the version with the theme
				file_put_contents($tmpPath.'/VERSION', $details['latest-version']);

				// If a theme is already installed that has that name, rename it to "$filePath-old"
				if (file_exists($filePath) && is_dir($filePath))
					rename($filePath, $filePath . "-old");

				// Then copy over the theme from the tmpPath to the final destination path
				rename($tmpPath, $filePath);

				// Then purge the -old directories
				if (file_exists($filePath . "-old"))
				{
					foreach(new RecursiveIteratorIterator(new RecursiveDirectoryIterator($filePath . "-old", FilesystemIterator::SKIP_DOTS), RecursiveIteratorIterator::CHILD_FIRST) as $path)
					$path->isDir() ? rmdir($path->getPathname()) : unlink($path->getPathname());

					rmdir($filePath . "-old");
				}

				// Purge the cache
				Yii::app()->cache->delete('settings_themes');
				return true;
			}

		}

		unlink($tmpPath.'.zip');
		throw new CHttpException(500, Yii::t('Api.theme', 'Unable to extract downloaded ZIP package'));
	}
public function actionInstall($name=false)
	{
		if ($name == false || defined('CII_CONFIG'))
			return false;

		$filePath 	= Yii::getPathOfAlias('base.themes').DS.$name;
		$details 	= $this->actionDetails($name);

		// If the theme is already installed, make sure it is the correct version, otherwise we'll be performing an upgrade
		if ($this->actionIsInstalled($name, true))
		{
			if (file_exists($filePath.DS.'VERSION'))
			{
				$version = file_get_contents($filePath.DS.'VERSION');

				if ($version == $details['latest-version'])
					return true;
			}
		}

		// Set several variables to store the various paths we'll need
		$tmpPath 	= Yii::getPathOfAlias('application.runtime.themes').DS.$name;
		$themesPath = Yii::getPathOfAlias('application.runtime').DS.'themes';
		$zipPath 	= $themesPath.DS.$details['sha'].'.zip';

		// Verify the temporary directory exists
		if (!file_exists($themesPath))
			mkdir($themesPath);

		// Download the ZIP package to the runtime/themes temporary directory
		
		if (!$this->downloadPackage($details['sha'], $details['file'], Yii::getPathOfAlias('application.runtime.themes')))
			throw new CHttpException(500, Yii::t('Api.theme', 'Failed to download theme package from Github. Source might be down'));

		$zip = new ZipArchive;

		// If we can open the file
		if ($zip->open($zipPath) === true)
		{
			// And we were able to extract it
			if ($zip->extractTo($themesPath.DS.$details['sha']))
			{
				// Close the ZIP connection
				$zip->close();

				// Delete the downloaded ZIP file
				unlink($zipPath);

				// Move the folders around so we're operating on the bare folder, then delete the teporary folder
				rename($themesPath.DS.$details['sha'].DS.'ciims-themes-'.$name.'-'.$details['latest-version'], $tmpPath);
				rmdir(str_replace('.zip', '', $zipPath));

				// Store the version with the theme
				file_put_contents($tmpPath.'/VERSION', $details['latest-version']);

				// If a theme is already installed that has that name, rename it to "$filePath-old"
				if (file_exists($filePath) && is_dir($filePath))
					rename($filePath, $filePath . "-old");

				// Then copy over the theme from the tmpPath to the final destination path
				rename($tmpPath, $filePath);

				// Then purge the -old directories
				if (file_exists($filePath . "-old"))
				{
					foreach(new RecursiveIteratorIterator(new RecursiveDirectoryIterator($filePath . "-old", FilesystemIterator::SKIP_DOTS), RecursiveIteratorIterator::CHILD_FIRST) as $path)
					$path->isDir() ? rmdir($path->getPathname()) : unlink($path->getPathname());

					rmdir($filePath . "-old");
				}

				// Purge the cache
				Yii::app()->cache->delete('settings_themes');
				return true;
			}

		}

		unlink($tmpPath.'.zip');
		throw new CHttpException(500, Yii::t('Api.theme', 'Unable to extract downloaded ZIP package'));
	}
public function actionInstall ( $ name = false ) { if ( $ name == false || defined ( 'CII_CONFIG' ) ) return false ; $ filePath = Yii :: getPathOfAlias ( 'base.themes' ) . DS . $ name ; $ details = $ this -> actionDetails ( $ name ) ; // If the theme is already installed, make sure it is the correct version, otherwise we'll be performing an upgrade if ( $ this -> actionIsInstalled ( $ name , true ) ) { if ( file_exists ( $ filePath . DS . 'VERSION' ) ) { $ version = file_get_contents ( $ filePath . DS . 'VERSION' ) ; if ( $ version == $ details [ 'latest-version' ] ) return true ; } } // Set several variables to store the various paths we'll need $ tmpPath = Yii :: getPathOfAlias ( 'application.runtime.themes' ) . DS . $ name ; $ themesPath = Yii :: getPathOfAlias ( 'application.runtime' ) . DS . 'themes' ; $ zipPath = $ themesPath . DS . $ details [ 'sha' ] . '.zip' ; // Verify the temporary directory exists if ( ! file_exists ( $ themesPath ) ) mkdir ( $ themesPath ) ; // Download the ZIP package to the runtime/themes temporary directory if ( ! $ this -> downloadPackage ( $ details [ 'sha' ] , $ details [ 'file' ] , Yii :: getPathOfAlias ( 'application.runtime.themes' ) ) ) throw new CHttpException ( 500 , Yii :: t ( 'Api.theme' , 'Failed to download theme package from Github. Source might be down' ) ) ; $ zip = new ZipArchive ; // If we can open the file if ( $ zip -> open ( $ zipPath ) === true ) { // And we were able to extract it if ( $ zip -> extractTo ( $ themesPath . DS . $ details [ 'sha' ] ) ) { // Close the ZIP connection $ zip -> close ( ) ; // Delete the downloaded ZIP file unlink ( $ zipPath ) ; // Move the folders around so we're operating on the bare folder, then delete the teporary folder rename ( $ themesPath . DS . $ details [ 'sha' ] . DS . 'ciims-themes-' . $ name . '-' . $ details [ 'latest-version' ] , $ tmpPath ) ; rmdir ( str_replace ( '.zip' , '' , $ zipPath ) ) ; // Store the version with the theme file_put_contents ( $ tmpPath . '/VERSION' , $ details [ 'latest-version' ] ) ; // If a theme is already installed that has that name, rename it to "$filePath-old" if ( file_exists ( $ filePath ) && is_dir ( $ filePath ) ) rename ( $ filePath , $ filePath . "-old" ) ; // Then copy over the theme from the tmpPath to the final destination path rename ( $ tmpPath , $ filePath ) ; // Then purge the -old directories if ( file_exists ( $ filePath . "-old" ) ) { foreach ( new RecursiveIteratorIterator ( new RecursiveDirectoryIterator ( $ filePath . "-old" , FilesystemIterator :: SKIP_DOTS ) , RecursiveIteratorIterator :: CHILD_FIRST ) as $ path ) $ path -> isDir ( ) ? rmdir ( $ path -> getPathname ( ) ) : unlink ( $ path -> getPathname ( ) ) ; rmdir ( $ filePath . "-old" ) ; } // Purge the cache Yii :: app ( ) -> cache -> delete ( 'settings_themes' ) ; return true ; } } unlink ( $ tmpPath . '.zip' ) ; throw new CHttpException ( 500 , Yii :: t ( 'Api.theme' , 'Unable to extract downloaded ZIP package' ) ) ; }
Installs and or updates a theme  using the provided name
@return boolean
Installs and or updates a theme using the provided name