| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  |  * @author Victor Dubiniuk <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  * @copyright Copyright (c) 2015, ownCloud, Inc. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  * @license AGPL-3.0 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  * This code is free software: you can redistribute it and/or modify | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  * it under the terms of the GNU Affero General Public License, version 3, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  * as published by the Free Software Foundation. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  * This program is distributed in the hope that it will be useful, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |  * GNU Affero General Public License for more details. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |  * You should have received a copy of the GNU Affero General Public License, version 3, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |  * along with this program.  If not, see <http://www.gnu.org/licenses/> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  | namespace Owncloud\Updater\Utils; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  | use Symfony\Component\Console\Output\OutputInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |  * Class AppManager | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |  * @package Owncloud\Updater\Utils | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 31 |  |  |  */ | 
            
                                                                        
                            
            
                                    
            
            
                | 32 |  |  | class AppManager { | 
            
                                                                        
                            
            
                                    
            
            
                | 33 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 34 |  |  | 	/** | 
            
                                                                        
                            
            
                                    
            
            
                | 35 |  |  | 	 * @var OccRunner $occRunner | 
            
                                                                        
                            
            
                                    
            
            
                | 36 |  |  | 	 */ | 
            
                                                                        
                            
            
                                    
            
            
                | 37 |  |  | 	protected $occRunner; | 
            
                                                                        
                            
            
                                    
            
            
                | 38 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 39 |  |  | 	/** | 
            
                                                                        
                            
            
                                    
            
            
                | 40 |  |  | 	 * @var array $disabledApps | 
            
                                                                        
                            
            
                                    
            
            
                | 41 |  |  | 	 */ | 
            
                                                                        
                            
            
                                    
            
            
                | 42 |  |  | 	protected $disabledApps = []; | 
            
                                                                        
                            
            
                                    
            
            
                | 43 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 44 |  |  | 	/** | 
            
                                                                        
                            
            
                                    
            
            
                | 45 |  |  | 	 * | 
            
                                                                        
                            
            
                                    
            
            
                | 46 |  |  | 	 * @param OccRunner $occRunner | 
            
                                                                        
                            
            
                                    
            
            
                | 47 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 | 5 |  | 	public function __construct(OccRunner $occRunner){ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 | 5 |  | 		$this->occRunner = $occRunner; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 50 | 5 |  | 	} | 
            
                                                                        
                            
            
                                    
            
            
                | 51 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 52 |  |  | 	/** | 
            
                                                                        
                            
            
                                    
            
            
                | 53 |  |  | 	 * @param $appId | 
            
                                                                        
                            
            
                                    
            
            
                | 54 |  |  | 	 * @return bool | 
            
                                                                        
                            
            
                                    
            
            
                | 55 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 | 1 |  | 	public function disableApp($appId){ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  | 		try{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 | 1 |  | 			$this->occRunner->run('app:disable', ['app-id' => $appId]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 | 1 |  | 		} catch (\Exception $e){ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  | 			return false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 | 1 |  | 		return true; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 63 |  |  | 	} | 
            
                                                                        
                            
            
                                    
            
            
                | 64 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 65 |  |  | 	/** | 
            
                                                                        
                            
            
                                    
            
            
                | 66 |  |  | 	 * @param $appId | 
            
                                                                        
                            
            
                                    
            
            
                | 67 |  |  | 	 * @return bool | 
            
                                                                        
                            
            
                                    
            
            
                | 68 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 | 1 |  | 	public function enableApp($appId){ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  | 		try{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 | 1 |  | 			$this->occRunner->run('app:enable', ['app-id' => $appId]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 | 1 |  | 			array_unshift($this->disabledApps, $appId); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 | 1 |  | 		} catch (\Exception $e){ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  | 			return false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 | 1 |  | 		return true; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 77 |  |  | 	} | 
            
                                                                        
                            
            
                                    
            
            
                | 78 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 79 |  |  | 	/** | 
            
                                                                        
                            
            
                                    
            
            
                | 80 |  |  | 	 * @return array | 
            
                                                                        
                            
            
                                    
            
            
                | 81 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  | 	public function getAllApps(){ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  | 		$shippedApps = $this->occRunner->runJson('app:list'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  | 		$allApps = array_merge(array_keys($shippedApps['enabled']), array_keys($shippedApps['disabled'])); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  | 		return $allApps; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 86 |  |  | 	} | 
            
                                                                        
                            
            
                                    
            
            
                | 87 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 88 |  |  | 	/** | 
            
                                                                        
                            
            
                                    
            
            
                | 89 |  |  | 	 * @return array | 
            
                                                                        
                            
            
                                    
            
            
                | 90 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  | 	public function getNotShippedApps(){ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  | 		$shippedApps = $this->occRunner->runJson('app:list', ['--shipped' => 'false']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  | 		$allApps = array_merge(array_keys($shippedApps['enabled']), array_keys($shippedApps['disabled'])); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  | 		return $allApps; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 95 |  |  | 	} | 
            
                                                                        
                            
            
                                    
            
            
                | 96 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 97 |  |  | 	/** | 
            
                                                                        
                            
            
                                    
            
            
                | 98 |  |  | 	 * @return array | 
            
                                                                        
                            
            
                                    
            
            
                | 99 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 | 2 |  | 	public function getShippedApps(){ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 | 2 |  | 		$shippedApps = $this->occRunner->runJson('app:list', ['--shipped' => 'true']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 | 2 |  | 		$allApps = array_merge(array_keys($shippedApps['enabled']), array_keys($shippedApps['disabled'])); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 | 2 |  | 		return $allApps; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 104 |  |  | 	} | 
            
                                                                        
                            
            
                                    
            
            
                | 105 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 106 |  |  | 	/** | 
            
                                                                        
                            
            
                                    
            
            
                | 107 |  |  | 	 * @param $appId | 
            
                                                                        
                            
            
                                    
            
            
                | 108 |  |  | 	 * @return string | 
            
                                                                        
                            
            
                                    
            
            
                | 109 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 | 1 |  | 	public function getAppPath($appId){ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  | 		try { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 | 1 |  | 			$response = $this->occRunner->run('app:getpath', ['app-id' => $appId]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 | 1 |  | 		} catch (\Exception $e) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  | 			return ''; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 | 1 |  | 		return trim($response); | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 117 |  |  | 	} | 
            
                                                        
            
                                    
            
            
                | 118 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 119 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 120 |  |  |  |