| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | declare(strict_types=1); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * @copyright Copyright (c) 2019, Morris Jobke <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  * @license GNU AGPL version 3 or any later version | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  * This program is free software: you can redistribute it and/or modify | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  * it under the terms of the GNU Affero General Public License as | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  * published by the Free Software Foundation, either version 3 of the | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  * License, or (at your option) any later version. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  * This program is distributed in the hope that it will be useful, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |  * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |  * GNU Affero General Public License for more details. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |  * You should have received a copy of the GNU Affero General Public License | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |  * along with this program.  If not, see <http://www.gnu.org/licenses/>. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  | namespace OC\Repair\NC17; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  | use OC\Files\AppData\Factory; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  | use OC\Template\SCSSCacher; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  | use OCA\Theming\ThemingDefaults; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  | use OCP\Files\IAppData; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  | use OCP\Files\NotFoundException; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  | use OCP\IConfig; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  | use OCP\Migration\IOutput; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  | use OCP\Migration\IRepairStep; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  | use OCP\Support\Subscription\IRegistry; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |  * @deprecated - can be removed in 18 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  | class SetEnterpriseLogo implements IRepairStep { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  | 	/** @var IConfig $config */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  | 	private $config; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  | 	/** @var IRegistry $subscriptionRegistry */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  | 	private $subscriptionRegistry; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  | 	/** @var IAppData $appData */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  | 	private $appData; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  | 	/** @var SCSSCacher $scssCacher */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  | 	private $scssCacher; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  | 	/** @var \OC_Defaults|ThemingDefaults */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  | 	private $themingDefaults; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  | 	public function getName(): string { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  | 		return 'Sets the enterprise logo'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  | 	public function __construct( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  | 		IConfig $config, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  | 		IRegistry $subscriptionRegistry, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  | 		Factory $appDataFactory, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  | 		SCSSCacher $SCSSCacher, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  | 		$ThemingDefaults | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  | 	) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  | 		$this->config = $config; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  | 		$this->subscriptionRegistry = $subscriptionRegistry; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  | 		$this->appData = $appDataFactory->get('theming'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  | 		$this->scssCacher = $SCSSCacher; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  | 		$this->themingDefaults = $ThemingDefaults; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  | 	} | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 72 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 73 |  |  | 	public function run(IOutput $output): void { | 
            
                                                                        
                            
            
                                    
            
            
                | 74 |  |  | 		// only run once | 
            
                                                                        
                            
            
                                    
            
            
                | 75 |  |  | 		if ($this->config->getAppValue('core', 'enterpriseLogoChecked') === 'yes') { | 
            
                                                                        
                            
            
                                    
            
            
                | 76 |  |  | 			$output->info('Repair step already executed'); | 
            
                                                                        
                            
            
                                    
            
            
                | 77 |  |  | 			return; | 
            
                                                                        
                            
            
                                    
            
            
                | 78 |  |  | 		} | 
            
                                                                        
                            
            
                                    
            
            
                | 79 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 80 |  |  | 		if (!$this->subscriptionRegistry->delegateHasValidSubscription()) { | 
            
                                                                        
                            
            
                                    
            
            
                | 81 |  |  | 			// no need to set the enterprise logo | 
            
                                                                        
                            
            
                                    
            
            
                | 82 |  |  | 			$this->config->setAppValue('core', 'enterpriseLogoChecked', 'yes'); | 
            
                                                                        
                            
            
                                    
            
            
                | 83 |  |  | 			return; | 
            
                                                                        
                            
            
                                    
            
            
                | 84 |  |  | 		} | 
            
                                                                        
                            
            
                                    
            
            
                | 85 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 86 |  |  | 		if ($this->themingDefaults instanceof ThemingDefaults) { | 
            
                                                                        
                            
            
                                    
            
            
                | 87 |  |  | 			$output->info('Theming is enabled - trying to set logo.'); | 
            
                                                                        
                            
            
                                    
            
            
                | 88 |  |  | 			try { | 
            
                                                                        
                            
            
                                    
            
            
                | 89 |  |  | 				$folder = $this->appData->getFolder('images'); | 
            
                                                                        
                            
            
                                    
            
            
                | 90 |  |  | 			} catch (NotFoundException $e) { | 
            
                                                                        
                            
            
                                    
            
            
                | 91 |  |  | 				$folder = $this->appData->newFolder('images'); | 
            
                                                                        
                            
            
                                    
            
            
                | 92 |  |  | 			} | 
            
                                                                        
                            
            
                                    
            
            
                | 93 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 94 |  |  | 			if (!$folder->fileExists('logo') || $folder->getFile('logo')->getSize() === 0) { | 
            
                                                                        
                            
            
                                    
            
            
                | 95 |  |  | 				$output->info('Logo does not exist yet - setting it.'); | 
            
                                                                        
                            
            
                                    
            
            
                | 96 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 97 |  |  | 				if ($folder->fileExists('logo')) { | 
            
                                                                        
                            
            
                                    
            
            
                | 98 |  |  | 					$folder->getFile('logo')->delete(); | 
            
                                                                        
                            
            
                                    
            
            
                | 99 |  |  | 				} | 
            
                                                                        
                            
            
                                    
            
            
                | 100 |  |  | 				$target = $folder->newFile('logo'); | 
            
                                                                        
                            
            
                                    
            
            
                | 101 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 102 |  |  | 				$target->putContent(file_get_contents(__DIR__ . '/../../../../core/img/logo/logo-enterprise.png')); | 
            
                                                                        
                            
            
                                    
            
            
                | 103 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 104 |  |  | 				$this->themingDefaults->set('logoMime', 'image/png'); | 
            
                                                                        
                            
            
                                    
            
            
                | 105 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 106 |  |  | 				$this->scssCacher->process(\OC::$SERVERROOT, 'core/css/css-variables.scss', 'core'); | 
            
                                                                        
                            
            
                                    
            
            
                | 107 |  |  | 			} else { | 
            
                                                                        
                            
            
                                    
            
            
                | 108 |  |  | 				$output->info('Logo already set - skipping.'); | 
            
                                                                        
                            
            
                                    
            
            
                | 109 |  |  | 			} | 
            
                                                                        
                            
            
                                    
            
            
                | 110 |  |  | 		} else { | 
            
                                                                        
                            
            
                                    
            
            
                | 111 |  |  | 			$output->info('Theming is not enabled - skipping.'); | 
            
                                                                        
                            
            
                                    
            
            
                | 112 |  |  | 		} | 
            
                                                                        
                            
            
                                    
            
            
                | 113 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 114 |  |  | 		// if all were done, no need to redo the repair during next upgrade | 
            
                                                                        
                            
            
                                    
            
            
                | 115 |  |  | 		$this->config->setAppValue('core', 'enterpriseLogoChecked', 'yes'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  | 	} | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 117 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 118 |  |  |  |