| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  |  * @copyright Copyright (c) 2016, ownCloud, Inc. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  * @author Joas Schilling <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  * @license AGPL-3.0 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  * This code is free software: you can redistribute it and/or modify | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  * it under the terms of the GNU Affero General Public License, version 3, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  * as published by the Free Software Foundation. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 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, version 3, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |  * along with this program.  If not, see <http://www.gnu.org/licenses/> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  | namespace OCA\Activity; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  | use OCA\Activity\AppInfo\Application; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  | use OCP\IDBConnection; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  | use OCP\Util; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |  * Handles the stream and mail queue of a user when he is being deleted | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  | class Hooks { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  | 	 * Delete remaining activities and emails when a user is deleted | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  | 	 * @param array $params The hook params | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 | 1 |  | 	static public function deleteUser($params) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 | 1 |  | 		$connection = \OC::$server->getDatabaseConnection(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 | 1 |  | 		self::deleteUserStream($params['uid']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 | 1 |  | 		self::deleteUserMailQueue($connection, $params['uid']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 | 1 |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  | 	 * Delete all items of the stream | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  | 	 * @param string $user | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 | 1 |  | 	static protected function deleteUserStream($user) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  | 		// Delete activity entries | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 | 1 |  | 		$app = new Application(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  | 		/** @var Data $activityData */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 | 1 |  | 		$activityData = $app->getContainer()->query(Data::class); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 | 1 |  | 		$activityData->deleteActivities(array('affecteduser' => $user)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 | 1 |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  | 	 * Delete all mail queue entries | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  | 	 * @param IDBConnection $connection | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  | 	 * @param string $user | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 62 |  |  | 	 */ | 
            
                                                                        
                            
            
                                    
            
            
                | 63 | 1 |  | 	static protected function deleteUserMailQueue(IDBConnection $connection, $user) { | 
            
                                                                        
                            
            
                                    
            
            
                | 64 |  |  | 		// Delete entries from mail queue | 
            
                                                                        
                            
            
                                    
            
            
                | 65 | 1 |  | 		$queryBuilder = $connection->getQueryBuilder(); | 
            
                                                                        
                            
            
                                    
            
            
                | 66 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 67 | 1 |  | 		$queryBuilder->delete('activity_mq') | 
            
                                                                        
                            
            
                                    
            
            
                | 68 | 1 |  | 			->where($queryBuilder->expr()->eq('amq_affecteduser', $queryBuilder->createParameter('user'))) | 
            
                                                                        
                            
            
                                    
            
            
                | 69 | 1 |  | 			->setParameter('user', $user); | 
            
                                                                        
                            
            
                                    
            
            
                | 70 | 1 |  | 		$queryBuilder->execute(); | 
            
                                                                        
                            
            
                                    
            
            
                | 71 | 1 |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  | 	static public function setDefaultsForUser($params) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  | 		$config = \OC::$server->getConfig(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  | 		if ($config->getUserValue($params['uid'], 'activity','notify_setting_batchtime', null) !== null) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  | 			// Already has settings | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  | 			return; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  | 		foreach ($config->getAppKeys('activity') as $key) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  | 			if (strpos($key, 'notify_') !== 0) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  | 				continue; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  | 			} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  | 			$config->setUserValue( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  | 				$params['uid'], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  | 				'activity', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  | 				$key, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  | 				$config->getAppValue('activity', $key) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  | 			); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  | 	 * Load additional scripts when the files app is visible | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  | 	public static function onLoadFilesAppScripts() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  | 		Util::addStyle('activity', 'style'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  | 		Util::addScript('activity', 'richObjectStringParser'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  | 		Util::addScript('activity', 'activitymodel'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  | 		Util::addScript('activity', 'activitycollection'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  | 		Util::addScript('activity', 'activitytabview'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  | 		Util::addScript('activity', 'filesplugin'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  | 	} | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 105 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 106 |  |  |  |