@@ -50,12 +50,12 @@ discard block |
||
| 50 | 50 | * @return array An array of Tag objects. |
| 51 | 51 | */ |
| 52 | 52 | public function loadTags($owners, $type) { |
| 53 | - if(!is_array($owners)) { |
|
| 53 | + if (!is_array($owners)) { |
|
| 54 | 54 | $owners = array($owners); |
| 55 | 55 | } |
| 56 | 56 | |
| 57 | - $sql = 'SELECT `id`, `uid`, `type`, `category` FROM `' . $this->getTableName() . '` ' |
|
| 58 | - . 'WHERE `uid` IN (' . str_repeat('?,', count($owners)-1) . '?) AND `type` = ? ORDER BY `category`'; |
|
| 57 | + $sql = 'SELECT `id`, `uid`, `type`, `category` FROM `'.$this->getTableName().'` ' |
|
| 58 | + . 'WHERE `uid` IN ('.str_repeat('?,', count($owners) - 1).'?) AND `type` = ? ORDER BY `category`'; |
|
| 59 | 59 | return $this->findEntities($sql, array_merge($owners, array($type))); |
| 60 | 60 | } |
| 61 | 61 | |
@@ -66,7 +66,7 @@ discard block |
||
| 66 | 66 | * @return bool |
| 67 | 67 | */ |
| 68 | 68 | public function tagExists($tag) { |
| 69 | - $sql = 'SELECT `id`, `uid`, `type`, `category` FROM `' . $this->getTableName() . '` ' |
|
| 69 | + $sql = 'SELECT `id`, `uid`, `type`, `category` FROM `'.$this->getTableName().'` ' |
|
| 70 | 70 | . 'WHERE `uid` = ? AND `type` = ? AND `category` = ?'; |
| 71 | 71 | try { |
| 72 | 72 | $this->findEntity($sql, array($tag->getOwner(), $tag->getType(), $tag->getName())); |
@@ -33,47 +33,47 @@ |
||
| 33 | 33 | */ |
| 34 | 34 | class TagMapper extends Mapper { |
| 35 | 35 | |
| 36 | - /** |
|
| 37 | - * Constructor. |
|
| 38 | - * |
|
| 39 | - * @param IDBConnection $db Instance of the Db abstraction layer. |
|
| 40 | - */ |
|
| 41 | - public function __construct(IDBConnection $db) { |
|
| 42 | - parent::__construct($db, 'vcategory', Tag::class); |
|
| 43 | - } |
|
| 36 | + /** |
|
| 37 | + * Constructor. |
|
| 38 | + * |
|
| 39 | + * @param IDBConnection $db Instance of the Db abstraction layer. |
|
| 40 | + */ |
|
| 41 | + public function __construct(IDBConnection $db) { |
|
| 42 | + parent::__construct($db, 'vcategory', Tag::class); |
|
| 43 | + } |
|
| 44 | 44 | |
| 45 | - /** |
|
| 46 | - * Load tags from the database. |
|
| 47 | - * |
|
| 48 | - * @param array|string $owners The user(s) whose tags we are going to load. |
|
| 49 | - * @param string $type The type of item for which we are loading tags. |
|
| 50 | - * @return array An array of Tag objects. |
|
| 51 | - */ |
|
| 52 | - public function loadTags($owners, $type) { |
|
| 53 | - if(!is_array($owners)) { |
|
| 54 | - $owners = array($owners); |
|
| 55 | - } |
|
| 45 | + /** |
|
| 46 | + * Load tags from the database. |
|
| 47 | + * |
|
| 48 | + * @param array|string $owners The user(s) whose tags we are going to load. |
|
| 49 | + * @param string $type The type of item for which we are loading tags. |
|
| 50 | + * @return array An array of Tag objects. |
|
| 51 | + */ |
|
| 52 | + public function loadTags($owners, $type) { |
|
| 53 | + if(!is_array($owners)) { |
|
| 54 | + $owners = array($owners); |
|
| 55 | + } |
|
| 56 | 56 | |
| 57 | - $sql = 'SELECT `id`, `uid`, `type`, `category` FROM `' . $this->getTableName() . '` ' |
|
| 58 | - . 'WHERE `uid` IN (' . str_repeat('?,', count($owners)-1) . '?) AND `type` = ? ORDER BY `category`'; |
|
| 59 | - return $this->findEntities($sql, array_merge($owners, array($type))); |
|
| 60 | - } |
|
| 57 | + $sql = 'SELECT `id`, `uid`, `type`, `category` FROM `' . $this->getTableName() . '` ' |
|
| 58 | + . 'WHERE `uid` IN (' . str_repeat('?,', count($owners)-1) . '?) AND `type` = ? ORDER BY `category`'; |
|
| 59 | + return $this->findEntities($sql, array_merge($owners, array($type))); |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | - /** |
|
| 63 | - * Check if a given Tag object already exists in the database. |
|
| 64 | - * |
|
| 65 | - * @param Tag $tag The tag to look for in the database. |
|
| 66 | - * @return bool |
|
| 67 | - */ |
|
| 68 | - public function tagExists($tag) { |
|
| 69 | - $sql = 'SELECT `id`, `uid`, `type`, `category` FROM `' . $this->getTableName() . '` ' |
|
| 70 | - . 'WHERE `uid` = ? AND `type` = ? AND `category` = ?'; |
|
| 71 | - try { |
|
| 72 | - $this->findEntity($sql, array($tag->getOwner(), $tag->getType(), $tag->getName())); |
|
| 73 | - } catch (DoesNotExistException $e) { |
|
| 74 | - return false; |
|
| 75 | - } |
|
| 76 | - return true; |
|
| 77 | - } |
|
| 62 | + /** |
|
| 63 | + * Check if a given Tag object already exists in the database. |
|
| 64 | + * |
|
| 65 | + * @param Tag $tag The tag to look for in the database. |
|
| 66 | + * @return bool |
|
| 67 | + */ |
|
| 68 | + public function tagExists($tag) { |
|
| 69 | + $sql = 'SELECT `id`, `uid`, `type`, `category` FROM `' . $this->getTableName() . '` ' |
|
| 70 | + . 'WHERE `uid` = ? AND `type` = ? AND `category` = ?'; |
|
| 71 | + try { |
|
| 72 | + $this->findEntity($sql, array($tag->getOwner(), $tag->getType(), $tag->getName())); |
|
| 73 | + } catch (DoesNotExistException $e) { |
|
| 74 | + return false; |
|
| 75 | + } |
|
| 76 | + return true; |
|
| 77 | + } |
|
| 78 | 78 | } |
| 79 | 79 | |
@@ -37,54 +37,54 @@ |
||
| 37 | 37 | */ |
| 38 | 38 | class Tag extends Entity { |
| 39 | 39 | |
| 40 | - protected $owner; |
|
| 41 | - protected $type; |
|
| 42 | - protected $name; |
|
| 40 | + protected $owner; |
|
| 41 | + protected $type; |
|
| 42 | + protected $name; |
|
| 43 | 43 | |
| 44 | - /** |
|
| 45 | - * Constructor. |
|
| 46 | - * |
|
| 47 | - * @param string $owner The tag's owner |
|
| 48 | - * @param string $type The type of item this tag is used for |
|
| 49 | - * @param string $name The tag's name |
|
| 50 | - */ |
|
| 51 | - public function __construct($owner = null, $type = null, $name = null) { |
|
| 52 | - $this->setOwner($owner); |
|
| 53 | - $this->setType($type); |
|
| 54 | - $this->setName($name); |
|
| 55 | - } |
|
| 44 | + /** |
|
| 45 | + * Constructor. |
|
| 46 | + * |
|
| 47 | + * @param string $owner The tag's owner |
|
| 48 | + * @param string $type The type of item this tag is used for |
|
| 49 | + * @param string $name The tag's name |
|
| 50 | + */ |
|
| 51 | + public function __construct($owner = null, $type = null, $name = null) { |
|
| 52 | + $this->setOwner($owner); |
|
| 53 | + $this->setType($type); |
|
| 54 | + $this->setName($name); |
|
| 55 | + } |
|
| 56 | 56 | |
| 57 | - /** |
|
| 58 | - * Transform a database columnname to a property |
|
| 59 | - * |
|
| 60 | - * @param string $columnName the name of the column |
|
| 61 | - * @return string the property name |
|
| 62 | - * @todo migrate existing database columns to the correct names |
|
| 63 | - * to be able to drop this direct mapping |
|
| 64 | - */ |
|
| 65 | - public function columnToProperty($columnName){ |
|
| 66 | - if ($columnName === 'category') { |
|
| 67 | - return 'name'; |
|
| 68 | - } elseif ($columnName === 'uid') { |
|
| 69 | - return 'owner'; |
|
| 70 | - } else { |
|
| 71 | - return parent::columnToProperty($columnName); |
|
| 72 | - } |
|
| 73 | - } |
|
| 57 | + /** |
|
| 58 | + * Transform a database columnname to a property |
|
| 59 | + * |
|
| 60 | + * @param string $columnName the name of the column |
|
| 61 | + * @return string the property name |
|
| 62 | + * @todo migrate existing database columns to the correct names |
|
| 63 | + * to be able to drop this direct mapping |
|
| 64 | + */ |
|
| 65 | + public function columnToProperty($columnName){ |
|
| 66 | + if ($columnName === 'category') { |
|
| 67 | + return 'name'; |
|
| 68 | + } elseif ($columnName === 'uid') { |
|
| 69 | + return 'owner'; |
|
| 70 | + } else { |
|
| 71 | + return parent::columnToProperty($columnName); |
|
| 72 | + } |
|
| 73 | + } |
|
| 74 | 74 | |
| 75 | - /** |
|
| 76 | - * Transform a property to a database column name |
|
| 77 | - * |
|
| 78 | - * @param string $property the name of the property |
|
| 79 | - * @return string the column name |
|
| 80 | - */ |
|
| 81 | - public function propertyToColumn($property){ |
|
| 82 | - if ($property === 'name') { |
|
| 83 | - return 'category'; |
|
| 84 | - } elseif ($property === 'owner') { |
|
| 85 | - return 'uid'; |
|
| 86 | - } else { |
|
| 87 | - return parent::propertyToColumn($property); |
|
| 88 | - } |
|
| 89 | - } |
|
| 75 | + /** |
|
| 76 | + * Transform a property to a database column name |
|
| 77 | + * |
|
| 78 | + * @param string $property the name of the property |
|
| 79 | + * @return string the column name |
|
| 80 | + */ |
|
| 81 | + public function propertyToColumn($property){ |
|
| 82 | + if ($property === 'name') { |
|
| 83 | + return 'category'; |
|
| 84 | + } elseif ($property === 'owner') { |
|
| 85 | + return 'uid'; |
|
| 86 | + } else { |
|
| 87 | + return parent::propertyToColumn($property); |
|
| 88 | + } |
|
| 89 | + } |
|
| 90 | 90 | } |
@@ -62,7 +62,7 @@ discard block |
||
| 62 | 62 | * @todo migrate existing database columns to the correct names |
| 63 | 63 | * to be able to drop this direct mapping |
| 64 | 64 | */ |
| 65 | - public function columnToProperty($columnName){ |
|
| 65 | + public function columnToProperty($columnName) { |
|
| 66 | 66 | if ($columnName === 'category') { |
| 67 | 67 | return 'name'; |
| 68 | 68 | } elseif ($columnName === 'uid') { |
@@ -78,7 +78,7 @@ discard block |
||
| 78 | 78 | * @param string $property the name of the property |
| 79 | 79 | * @return string the column name |
| 80 | 80 | */ |
| 81 | - public function propertyToColumn($property){ |
|
| 81 | + public function propertyToColumn($property) { |
|
| 82 | 82 | if ($property === 'name') { |
| 83 | 83 | return 'category'; |
| 84 | 84 | } elseif ($property === 'owner') { |
@@ -40,53 +40,53 @@ |
||
| 40 | 40 | |
| 41 | 41 | class TagManager implements \OCP\ITagManager { |
| 42 | 42 | |
| 43 | - /** |
|
| 44 | - * User session |
|
| 45 | - * |
|
| 46 | - * @var \OCP\IUserSession |
|
| 47 | - */ |
|
| 48 | - private $userSession; |
|
| 43 | + /** |
|
| 44 | + * User session |
|
| 45 | + * |
|
| 46 | + * @var \OCP\IUserSession |
|
| 47 | + */ |
|
| 48 | + private $userSession; |
|
| 49 | 49 | |
| 50 | - /** |
|
| 51 | - * TagMapper |
|
| 52 | - * |
|
| 53 | - * @var TagMapper |
|
| 54 | - */ |
|
| 55 | - private $mapper; |
|
| 50 | + /** |
|
| 51 | + * TagMapper |
|
| 52 | + * |
|
| 53 | + * @var TagMapper |
|
| 54 | + */ |
|
| 55 | + private $mapper; |
|
| 56 | 56 | |
| 57 | - /** |
|
| 58 | - * Constructor. |
|
| 59 | - * |
|
| 60 | - * @param TagMapper $mapper Instance of the TagMapper abstraction layer. |
|
| 61 | - * @param \OCP\IUserSession $userSession the user session |
|
| 62 | - */ |
|
| 63 | - public function __construct(TagMapper $mapper, \OCP\IUserSession $userSession) { |
|
| 64 | - $this->mapper = $mapper; |
|
| 65 | - $this->userSession = $userSession; |
|
| 57 | + /** |
|
| 58 | + * Constructor. |
|
| 59 | + * |
|
| 60 | + * @param TagMapper $mapper Instance of the TagMapper abstraction layer. |
|
| 61 | + * @param \OCP\IUserSession $userSession the user session |
|
| 62 | + */ |
|
| 63 | + public function __construct(TagMapper $mapper, \OCP\IUserSession $userSession) { |
|
| 64 | + $this->mapper = $mapper; |
|
| 65 | + $this->userSession = $userSession; |
|
| 66 | 66 | |
| 67 | - } |
|
| 67 | + } |
|
| 68 | 68 | |
| 69 | - /** |
|
| 70 | - * Create a new \OCP\ITags instance and load tags from db. |
|
| 71 | - * |
|
| 72 | - * @see \OCP\ITags |
|
| 73 | - * @param string $type The type identifier e.g. 'contact' or 'event'. |
|
| 74 | - * @param array $defaultTags An array of default tags to be used if none are stored. |
|
| 75 | - * @param boolean $includeShared Whether to include tags for items shared with this user by others. |
|
| 76 | - * @param string $userId user for which to retrieve the tags, defaults to the currently |
|
| 77 | - * logged in user |
|
| 78 | - * @return \OCP\ITags |
|
| 79 | - */ |
|
| 80 | - public function load($type, $defaultTags = array(), $includeShared = false, $userId = null) { |
|
| 81 | - if (is_null($userId)) { |
|
| 82 | - $user = $this->userSession->getUser(); |
|
| 83 | - if ($user === null) { |
|
| 84 | - // nothing we can do without a user |
|
| 85 | - return null; |
|
| 86 | - } |
|
| 87 | - $userId = $this->userSession->getUser()->getUId(); |
|
| 88 | - } |
|
| 89 | - return new Tags($this->mapper, $userId, $type, $defaultTags, $includeShared); |
|
| 90 | - } |
|
| 69 | + /** |
|
| 70 | + * Create a new \OCP\ITags instance and load tags from db. |
|
| 71 | + * |
|
| 72 | + * @see \OCP\ITags |
|
| 73 | + * @param string $type The type identifier e.g. 'contact' or 'event'. |
|
| 74 | + * @param array $defaultTags An array of default tags to be used if none are stored. |
|
| 75 | + * @param boolean $includeShared Whether to include tags for items shared with this user by others. |
|
| 76 | + * @param string $userId user for which to retrieve the tags, defaults to the currently |
|
| 77 | + * logged in user |
|
| 78 | + * @return \OCP\ITags |
|
| 79 | + */ |
|
| 80 | + public function load($type, $defaultTags = array(), $includeShared = false, $userId = null) { |
|
| 81 | + if (is_null($userId)) { |
|
| 82 | + $user = $this->userSession->getUser(); |
|
| 83 | + if ($user === null) { |
|
| 84 | + // nothing we can do without a user |
|
| 85 | + return null; |
|
| 86 | + } |
|
| 87 | + $userId = $this->userSession->getUser()->getUId(); |
|
| 88 | + } |
|
| 89 | + return new Tags($this->mapper, $userId, $type, $defaultTags, $includeShared); |
|
| 90 | + } |
|
| 91 | 91 | |
| 92 | 92 | } |
@@ -41,10 +41,10 @@ discard block |
||
| 41 | 41 | public function search($pattern, $searchProperties = array(), $options = array()) { |
| 42 | 42 | $this->loadAddressBooks(); |
| 43 | 43 | $result = array(); |
| 44 | - foreach($this->addressBooks as $addressBook) { |
|
| 44 | + foreach ($this->addressBooks as $addressBook) { |
|
| 45 | 45 | $r = $addressBook->search($pattern, $searchProperties, $options); |
| 46 | 46 | $contacts = array(); |
| 47 | - foreach($r as $c){ |
|
| 47 | + foreach ($r as $c) { |
|
| 48 | 48 | $c['addressbook-key'] = $addressBook->getKey(); |
| 49 | 49 | $contacts[] = $c; |
| 50 | 50 | } |
@@ -124,7 +124,7 @@ discard block |
||
| 124 | 124 | public function getAddressBooks() { |
| 125 | 125 | $this->loadAddressBooks(); |
| 126 | 126 | $result = array(); |
| 127 | - foreach($this->addressBooks as $addressBook) { |
|
| 127 | + foreach ($this->addressBooks as $addressBook) { |
|
| 128 | 128 | $result[$addressBook->getKey()] = $addressBook->getDisplayName(); |
| 129 | 129 | } |
| 130 | 130 | |
@@ -181,7 +181,7 @@ discard block |
||
| 181 | 181 | */ |
| 182 | 182 | protected function loadAddressBooks() |
| 183 | 183 | { |
| 184 | - foreach($this->addressBookLoaders as $callable) { |
|
| 184 | + foreach ($this->addressBookLoaders as $callable) { |
|
| 185 | 185 | $callable($this); |
| 186 | 186 | } |
| 187 | 187 | $this->addressBookLoaders = array(); |
@@ -27,180 +27,180 @@ |
||
| 27 | 27 | |
| 28 | 28 | namespace OC { |
| 29 | 29 | |
| 30 | - class ContactsManager implements \OCP\Contacts\IManager { |
|
| 31 | - |
|
| 32 | - /** |
|
| 33 | - * This function is used to search and find contacts within the users address books. |
|
| 34 | - * In case $pattern is empty all contacts will be returned. |
|
| 35 | - * |
|
| 36 | - * @param string $pattern which should match within the $searchProperties |
|
| 37 | - * @param array $searchProperties defines the properties within the query pattern should match |
|
| 38 | - * @param array $options - for future use. One should always have options! |
|
| 39 | - * @return array an array of contacts which are arrays of key-value-pairs |
|
| 40 | - */ |
|
| 41 | - public function search($pattern, $searchProperties = array(), $options = array()) { |
|
| 42 | - $this->loadAddressBooks(); |
|
| 43 | - $result = array(); |
|
| 44 | - foreach($this->addressBooks as $addressBook) { |
|
| 45 | - $r = $addressBook->search($pattern, $searchProperties, $options); |
|
| 46 | - $contacts = array(); |
|
| 47 | - foreach($r as $c){ |
|
| 48 | - $c['addressbook-key'] = $addressBook->getKey(); |
|
| 49 | - $contacts[] = $c; |
|
| 50 | - } |
|
| 51 | - $result = array_merge($result, $contacts); |
|
| 52 | - } |
|
| 53 | - |
|
| 54 | - return $result; |
|
| 55 | - } |
|
| 56 | - |
|
| 57 | - /** |
|
| 58 | - * This function can be used to delete the contact identified by the given id |
|
| 59 | - * |
|
| 60 | - * @param object $id the unique identifier to a contact |
|
| 61 | - * @param string $addressBookKey identifier of the address book in which the contact shall be deleted |
|
| 62 | - * @return bool successful or not |
|
| 63 | - */ |
|
| 64 | - public function delete($id, $addressBookKey) { |
|
| 65 | - $addressBook = $this->getAddressBook($addressBookKey); |
|
| 66 | - if (!$addressBook) { |
|
| 67 | - return null; |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - if ($addressBook->getPermissions() & \OCP\Constants::PERMISSION_DELETE) { |
|
| 71 | - return $addressBook->delete($id); |
|
| 72 | - } |
|
| 73 | - |
|
| 74 | - return null; |
|
| 75 | - } |
|
| 76 | - |
|
| 77 | - /** |
|
| 78 | - * This function is used to create a new contact if 'id' is not given or not present. |
|
| 79 | - * Otherwise the contact will be updated by replacing the entire data set. |
|
| 80 | - * |
|
| 81 | - * @param array $properties this array if key-value-pairs defines a contact |
|
| 82 | - * @param string $addressBookKey identifier of the address book in which the contact shall be created or updated |
|
| 83 | - * @return array representing the contact just created or updated |
|
| 84 | - */ |
|
| 85 | - public function createOrUpdate($properties, $addressBookKey) { |
|
| 86 | - $addressBook = $this->getAddressBook($addressBookKey); |
|
| 87 | - if (!$addressBook) { |
|
| 88 | - return null; |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - if ($addressBook->getPermissions() & \OCP\Constants::PERMISSION_CREATE) { |
|
| 92 | - return $addressBook->createOrUpdate($properties); |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - return null; |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - /** |
|
| 99 | - * Check if contacts are available (e.g. contacts app enabled) |
|
| 100 | - * |
|
| 101 | - * @return bool true if enabled, false if not |
|
| 102 | - */ |
|
| 103 | - public function isEnabled() { |
|
| 104 | - return !empty($this->addressBooks) || !empty($this->addressBookLoaders); |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - /** |
|
| 108 | - * @param \OCP\IAddressBook $addressBook |
|
| 109 | - */ |
|
| 110 | - public function registerAddressBook(\OCP\IAddressBook $addressBook) { |
|
| 111 | - $this->addressBooks[$addressBook->getKey()] = $addressBook; |
|
| 112 | - } |
|
| 113 | - |
|
| 114 | - /** |
|
| 115 | - * @param \OCP\IAddressBook $addressBook |
|
| 116 | - */ |
|
| 117 | - public function unregisterAddressBook(\OCP\IAddressBook $addressBook) { |
|
| 118 | - unset($this->addressBooks[$addressBook->getKey()]); |
|
| 119 | - } |
|
| 120 | - |
|
| 121 | - /** |
|
| 122 | - * Return a list of the user's addressbooks display names |
|
| 123 | - * ! The addressBook displayName are not unique, please use getUserAddressBooks |
|
| 124 | - * |
|
| 125 | - * @return array |
|
| 126 | - * @since 6.0.0 |
|
| 127 | - * @deprecated 16.0.0 - Use `$this->getUserAddressBooks()` instead |
|
| 128 | - */ |
|
| 129 | - public function getAddressBooks() { |
|
| 130 | - $this->loadAddressBooks(); |
|
| 131 | - $result = array(); |
|
| 132 | - foreach($this->addressBooks as $addressBook) { |
|
| 133 | - $result[$addressBook->getKey()] = $addressBook->getDisplayName(); |
|
| 134 | - } |
|
| 135 | - |
|
| 136 | - return $result; |
|
| 137 | - } |
|
| 138 | - |
|
| 139 | - /** |
|
| 140 | - * Return a list of the user's addressbooks |
|
| 141 | - * |
|
| 142 | - * @return IAddressBook[] |
|
| 143 | - * @since 16.0.0 |
|
| 144 | - */ |
|
| 145 | - public function getUserAddressBooks(): Array { |
|
| 146 | - $this->loadAddressBooks(); |
|
| 147 | - return $this->addressBooks; |
|
| 148 | - } |
|
| 149 | - |
|
| 150 | - /** |
|
| 151 | - * removes all registered address book instances |
|
| 152 | - */ |
|
| 153 | - public function clear() { |
|
| 154 | - $this->addressBooks = array(); |
|
| 155 | - $this->addressBookLoaders = array(); |
|
| 156 | - } |
|
| 157 | - |
|
| 158 | - /** |
|
| 159 | - * @var \OCP\IAddressBook[] which holds all registered address books |
|
| 160 | - */ |
|
| 161 | - private $addressBooks = array(); |
|
| 162 | - |
|
| 163 | - /** |
|
| 164 | - * @var \Closure[] to call to load/register address books |
|
| 165 | - */ |
|
| 166 | - private $addressBookLoaders = array(); |
|
| 167 | - |
|
| 168 | - /** |
|
| 169 | - * In order to improve lazy loading a closure can be registered which will be called in case |
|
| 170 | - * address books are actually requested |
|
| 171 | - * |
|
| 172 | - * @param \Closure $callable |
|
| 173 | - */ |
|
| 174 | - public function register(\Closure $callable) |
|
| 175 | - { |
|
| 176 | - $this->addressBookLoaders[] = $callable; |
|
| 177 | - } |
|
| 178 | - |
|
| 179 | - /** |
|
| 180 | - * Get (and load when needed) the address book for $key |
|
| 181 | - * |
|
| 182 | - * @param string $addressBookKey |
|
| 183 | - * @return \OCP\IAddressBook |
|
| 184 | - */ |
|
| 185 | - protected function getAddressBook($addressBookKey) |
|
| 186 | - { |
|
| 187 | - $this->loadAddressBooks(); |
|
| 188 | - if (!array_key_exists($addressBookKey, $this->addressBooks)) { |
|
| 189 | - return null; |
|
| 190 | - } |
|
| 191 | - |
|
| 192 | - return $this->addressBooks[$addressBookKey]; |
|
| 193 | - } |
|
| 194 | - |
|
| 195 | - /** |
|
| 196 | - * Load all address books registered with 'register' |
|
| 197 | - */ |
|
| 198 | - protected function loadAddressBooks() |
|
| 199 | - { |
|
| 200 | - foreach($this->addressBookLoaders as $callable) { |
|
| 201 | - $callable($this); |
|
| 202 | - } |
|
| 203 | - $this->addressBookLoaders = array(); |
|
| 204 | - } |
|
| 205 | - } |
|
| 30 | + class ContactsManager implements \OCP\Contacts\IManager { |
|
| 31 | + |
|
| 32 | + /** |
|
| 33 | + * This function is used to search and find contacts within the users address books. |
|
| 34 | + * In case $pattern is empty all contacts will be returned. |
|
| 35 | + * |
|
| 36 | + * @param string $pattern which should match within the $searchProperties |
|
| 37 | + * @param array $searchProperties defines the properties within the query pattern should match |
|
| 38 | + * @param array $options - for future use. One should always have options! |
|
| 39 | + * @return array an array of contacts which are arrays of key-value-pairs |
|
| 40 | + */ |
|
| 41 | + public function search($pattern, $searchProperties = array(), $options = array()) { |
|
| 42 | + $this->loadAddressBooks(); |
|
| 43 | + $result = array(); |
|
| 44 | + foreach($this->addressBooks as $addressBook) { |
|
| 45 | + $r = $addressBook->search($pattern, $searchProperties, $options); |
|
| 46 | + $contacts = array(); |
|
| 47 | + foreach($r as $c){ |
|
| 48 | + $c['addressbook-key'] = $addressBook->getKey(); |
|
| 49 | + $contacts[] = $c; |
|
| 50 | + } |
|
| 51 | + $result = array_merge($result, $contacts); |
|
| 52 | + } |
|
| 53 | + |
|
| 54 | + return $result; |
|
| 55 | + } |
|
| 56 | + |
|
| 57 | + /** |
|
| 58 | + * This function can be used to delete the contact identified by the given id |
|
| 59 | + * |
|
| 60 | + * @param object $id the unique identifier to a contact |
|
| 61 | + * @param string $addressBookKey identifier of the address book in which the contact shall be deleted |
|
| 62 | + * @return bool successful or not |
|
| 63 | + */ |
|
| 64 | + public function delete($id, $addressBookKey) { |
|
| 65 | + $addressBook = $this->getAddressBook($addressBookKey); |
|
| 66 | + if (!$addressBook) { |
|
| 67 | + return null; |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + if ($addressBook->getPermissions() & \OCP\Constants::PERMISSION_DELETE) { |
|
| 71 | + return $addressBook->delete($id); |
|
| 72 | + } |
|
| 73 | + |
|
| 74 | + return null; |
|
| 75 | + } |
|
| 76 | + |
|
| 77 | + /** |
|
| 78 | + * This function is used to create a new contact if 'id' is not given or not present. |
|
| 79 | + * Otherwise the contact will be updated by replacing the entire data set. |
|
| 80 | + * |
|
| 81 | + * @param array $properties this array if key-value-pairs defines a contact |
|
| 82 | + * @param string $addressBookKey identifier of the address book in which the contact shall be created or updated |
|
| 83 | + * @return array representing the contact just created or updated |
|
| 84 | + */ |
|
| 85 | + public function createOrUpdate($properties, $addressBookKey) { |
|
| 86 | + $addressBook = $this->getAddressBook($addressBookKey); |
|
| 87 | + if (!$addressBook) { |
|
| 88 | + return null; |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + if ($addressBook->getPermissions() & \OCP\Constants::PERMISSION_CREATE) { |
|
| 92 | + return $addressBook->createOrUpdate($properties); |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + return null; |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + /** |
|
| 99 | + * Check if contacts are available (e.g. contacts app enabled) |
|
| 100 | + * |
|
| 101 | + * @return bool true if enabled, false if not |
|
| 102 | + */ |
|
| 103 | + public function isEnabled() { |
|
| 104 | + return !empty($this->addressBooks) || !empty($this->addressBookLoaders); |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + /** |
|
| 108 | + * @param \OCP\IAddressBook $addressBook |
|
| 109 | + */ |
|
| 110 | + public function registerAddressBook(\OCP\IAddressBook $addressBook) { |
|
| 111 | + $this->addressBooks[$addressBook->getKey()] = $addressBook; |
|
| 112 | + } |
|
| 113 | + |
|
| 114 | + /** |
|
| 115 | + * @param \OCP\IAddressBook $addressBook |
|
| 116 | + */ |
|
| 117 | + public function unregisterAddressBook(\OCP\IAddressBook $addressBook) { |
|
| 118 | + unset($this->addressBooks[$addressBook->getKey()]); |
|
| 119 | + } |
|
| 120 | + |
|
| 121 | + /** |
|
| 122 | + * Return a list of the user's addressbooks display names |
|
| 123 | + * ! The addressBook displayName are not unique, please use getUserAddressBooks |
|
| 124 | + * |
|
| 125 | + * @return array |
|
| 126 | + * @since 6.0.0 |
|
| 127 | + * @deprecated 16.0.0 - Use `$this->getUserAddressBooks()` instead |
|
| 128 | + */ |
|
| 129 | + public function getAddressBooks() { |
|
| 130 | + $this->loadAddressBooks(); |
|
| 131 | + $result = array(); |
|
| 132 | + foreach($this->addressBooks as $addressBook) { |
|
| 133 | + $result[$addressBook->getKey()] = $addressBook->getDisplayName(); |
|
| 134 | + } |
|
| 135 | + |
|
| 136 | + return $result; |
|
| 137 | + } |
|
| 138 | + |
|
| 139 | + /** |
|
| 140 | + * Return a list of the user's addressbooks |
|
| 141 | + * |
|
| 142 | + * @return IAddressBook[] |
|
| 143 | + * @since 16.0.0 |
|
| 144 | + */ |
|
| 145 | + public function getUserAddressBooks(): Array { |
|
| 146 | + $this->loadAddressBooks(); |
|
| 147 | + return $this->addressBooks; |
|
| 148 | + } |
|
| 149 | + |
|
| 150 | + /** |
|
| 151 | + * removes all registered address book instances |
|
| 152 | + */ |
|
| 153 | + public function clear() { |
|
| 154 | + $this->addressBooks = array(); |
|
| 155 | + $this->addressBookLoaders = array(); |
|
| 156 | + } |
|
| 157 | + |
|
| 158 | + /** |
|
| 159 | + * @var \OCP\IAddressBook[] which holds all registered address books |
|
| 160 | + */ |
|
| 161 | + private $addressBooks = array(); |
|
| 162 | + |
|
| 163 | + /** |
|
| 164 | + * @var \Closure[] to call to load/register address books |
|
| 165 | + */ |
|
| 166 | + private $addressBookLoaders = array(); |
|
| 167 | + |
|
| 168 | + /** |
|
| 169 | + * In order to improve lazy loading a closure can be registered which will be called in case |
|
| 170 | + * address books are actually requested |
|
| 171 | + * |
|
| 172 | + * @param \Closure $callable |
|
| 173 | + */ |
|
| 174 | + public function register(\Closure $callable) |
|
| 175 | + { |
|
| 176 | + $this->addressBookLoaders[] = $callable; |
|
| 177 | + } |
|
| 178 | + |
|
| 179 | + /** |
|
| 180 | + * Get (and load when needed) the address book for $key |
|
| 181 | + * |
|
| 182 | + * @param string $addressBookKey |
|
| 183 | + * @return \OCP\IAddressBook |
|
| 184 | + */ |
|
| 185 | + protected function getAddressBook($addressBookKey) |
|
| 186 | + { |
|
| 187 | + $this->loadAddressBooks(); |
|
| 188 | + if (!array_key_exists($addressBookKey, $this->addressBooks)) { |
|
| 189 | + return null; |
|
| 190 | + } |
|
| 191 | + |
|
| 192 | + return $this->addressBooks[$addressBookKey]; |
|
| 193 | + } |
|
| 194 | + |
|
| 195 | + /** |
|
| 196 | + * Load all address books registered with 'register' |
|
| 197 | + */ |
|
| 198 | + protected function loadAddressBooks() |
|
| 199 | + { |
|
| 200 | + foreach($this->addressBookLoaders as $callable) { |
|
| 201 | + $callable($this); |
|
| 202 | + } |
|
| 203 | + $this->addressBookLoaders = array(); |
|
| 204 | + } |
|
| 205 | + } |
|
| 206 | 206 | } |
@@ -134,7 +134,7 @@ |
||
| 134 | 134 | } |
| 135 | 135 | if(is_dir($source.'/'.$file)) { |
| 136 | 136 | $this->addRecursive($path.'/'.$file, $source.'/'.$file); |
| 137 | - }else{ |
|
| 137 | + } else{ |
|
| 138 | 138 | $this->addFile($path.'/'.$file, $source.'/'.$file); |
| 139 | 139 | } |
| 140 | 140 | } |
@@ -33,111 +33,111 @@ |
||
| 33 | 33 | namespace OC\Archive; |
| 34 | 34 | |
| 35 | 35 | abstract class Archive { |
| 36 | - /** |
|
| 37 | - * @param $source |
|
| 38 | - */ |
|
| 39 | - public abstract function __construct($source); |
|
| 40 | - /** |
|
| 41 | - * add an empty folder to the archive |
|
| 42 | - * @param string $path |
|
| 43 | - * @return bool |
|
| 44 | - */ |
|
| 45 | - public abstract function addFolder($path); |
|
| 46 | - /** |
|
| 47 | - * add a file to the archive |
|
| 48 | - * @param string $path |
|
| 49 | - * @param string $source either a local file or string data |
|
| 50 | - * @return bool |
|
| 51 | - */ |
|
| 52 | - public abstract function addFile($path, $source=''); |
|
| 53 | - /** |
|
| 54 | - * rename a file or folder in the archive |
|
| 55 | - * @param string $source |
|
| 56 | - * @param string $dest |
|
| 57 | - * @return bool |
|
| 58 | - */ |
|
| 59 | - public abstract function rename($source, $dest); |
|
| 60 | - /** |
|
| 61 | - * get the uncompressed size of a file in the archive |
|
| 62 | - * @param string $path |
|
| 63 | - * @return int |
|
| 64 | - */ |
|
| 65 | - public abstract function filesize($path); |
|
| 66 | - /** |
|
| 67 | - * get the last modified time of a file in the archive |
|
| 68 | - * @param string $path |
|
| 69 | - * @return int |
|
| 70 | - */ |
|
| 71 | - public abstract function mtime($path); |
|
| 72 | - /** |
|
| 73 | - * get the files in a folder |
|
| 74 | - * @param string $path |
|
| 75 | - * @return array |
|
| 76 | - */ |
|
| 77 | - public abstract function getFolder($path); |
|
| 78 | - /** |
|
| 79 | - * get all files in the archive |
|
| 80 | - * @return array |
|
| 81 | - */ |
|
| 82 | - public abstract function getFiles(); |
|
| 83 | - /** |
|
| 84 | - * get the content of a file |
|
| 85 | - * @param string $path |
|
| 86 | - * @return string |
|
| 87 | - */ |
|
| 88 | - public abstract function getFile($path); |
|
| 89 | - /** |
|
| 90 | - * extract a single file from the archive |
|
| 91 | - * @param string $path |
|
| 92 | - * @param string $dest |
|
| 93 | - * @return bool |
|
| 94 | - */ |
|
| 95 | - public abstract function extractFile($path, $dest); |
|
| 96 | - /** |
|
| 97 | - * extract the archive |
|
| 98 | - * @param string $dest |
|
| 99 | - * @return bool |
|
| 100 | - */ |
|
| 101 | - public abstract function extract($dest); |
|
| 102 | - /** |
|
| 103 | - * check if a file or folder exists in the archive |
|
| 104 | - * @param string $path |
|
| 105 | - * @return bool |
|
| 106 | - */ |
|
| 107 | - public abstract function fileExists($path); |
|
| 108 | - /** |
|
| 109 | - * remove a file or folder from the archive |
|
| 110 | - * @param string $path |
|
| 111 | - * @return bool |
|
| 112 | - */ |
|
| 113 | - public abstract function remove($path); |
|
| 114 | - /** |
|
| 115 | - * get a file handler |
|
| 116 | - * @param string $path |
|
| 117 | - * @param string $mode |
|
| 118 | - * @return resource |
|
| 119 | - */ |
|
| 120 | - public abstract function getStream($path, $mode); |
|
| 121 | - /** |
|
| 122 | - * add a folder and all its content |
|
| 123 | - * @param string $path |
|
| 124 | - * @param string $source |
|
| 125 | - * @return boolean|null |
|
| 126 | - */ |
|
| 127 | - public function addRecursive($path, $source) { |
|
| 128 | - $dh = opendir($source); |
|
| 129 | - if(is_resource($dh)) { |
|
| 130 | - $this->addFolder($path); |
|
| 131 | - while (($file = readdir($dh)) !== false) { |
|
| 132 | - if($file === '.' || $file === '..') { |
|
| 133 | - continue; |
|
| 134 | - } |
|
| 135 | - if(is_dir($source.'/'.$file)) { |
|
| 136 | - $this->addRecursive($path.'/'.$file, $source.'/'.$file); |
|
| 137 | - }else{ |
|
| 138 | - $this->addFile($path.'/'.$file, $source.'/'.$file); |
|
| 139 | - } |
|
| 140 | - } |
|
| 141 | - } |
|
| 142 | - } |
|
| 36 | + /** |
|
| 37 | + * @param $source |
|
| 38 | + */ |
|
| 39 | + public abstract function __construct($source); |
|
| 40 | + /** |
|
| 41 | + * add an empty folder to the archive |
|
| 42 | + * @param string $path |
|
| 43 | + * @return bool |
|
| 44 | + */ |
|
| 45 | + public abstract function addFolder($path); |
|
| 46 | + /** |
|
| 47 | + * add a file to the archive |
|
| 48 | + * @param string $path |
|
| 49 | + * @param string $source either a local file or string data |
|
| 50 | + * @return bool |
|
| 51 | + */ |
|
| 52 | + public abstract function addFile($path, $source=''); |
|
| 53 | + /** |
|
| 54 | + * rename a file or folder in the archive |
|
| 55 | + * @param string $source |
|
| 56 | + * @param string $dest |
|
| 57 | + * @return bool |
|
| 58 | + */ |
|
| 59 | + public abstract function rename($source, $dest); |
|
| 60 | + /** |
|
| 61 | + * get the uncompressed size of a file in the archive |
|
| 62 | + * @param string $path |
|
| 63 | + * @return int |
|
| 64 | + */ |
|
| 65 | + public abstract function filesize($path); |
|
| 66 | + /** |
|
| 67 | + * get the last modified time of a file in the archive |
|
| 68 | + * @param string $path |
|
| 69 | + * @return int |
|
| 70 | + */ |
|
| 71 | + public abstract function mtime($path); |
|
| 72 | + /** |
|
| 73 | + * get the files in a folder |
|
| 74 | + * @param string $path |
|
| 75 | + * @return array |
|
| 76 | + */ |
|
| 77 | + public abstract function getFolder($path); |
|
| 78 | + /** |
|
| 79 | + * get all files in the archive |
|
| 80 | + * @return array |
|
| 81 | + */ |
|
| 82 | + public abstract function getFiles(); |
|
| 83 | + /** |
|
| 84 | + * get the content of a file |
|
| 85 | + * @param string $path |
|
| 86 | + * @return string |
|
| 87 | + */ |
|
| 88 | + public abstract function getFile($path); |
|
| 89 | + /** |
|
| 90 | + * extract a single file from the archive |
|
| 91 | + * @param string $path |
|
| 92 | + * @param string $dest |
|
| 93 | + * @return bool |
|
| 94 | + */ |
|
| 95 | + public abstract function extractFile($path, $dest); |
|
| 96 | + /** |
|
| 97 | + * extract the archive |
|
| 98 | + * @param string $dest |
|
| 99 | + * @return bool |
|
| 100 | + */ |
|
| 101 | + public abstract function extract($dest); |
|
| 102 | + /** |
|
| 103 | + * check if a file or folder exists in the archive |
|
| 104 | + * @param string $path |
|
| 105 | + * @return bool |
|
| 106 | + */ |
|
| 107 | + public abstract function fileExists($path); |
|
| 108 | + /** |
|
| 109 | + * remove a file or folder from the archive |
|
| 110 | + * @param string $path |
|
| 111 | + * @return bool |
|
| 112 | + */ |
|
| 113 | + public abstract function remove($path); |
|
| 114 | + /** |
|
| 115 | + * get a file handler |
|
| 116 | + * @param string $path |
|
| 117 | + * @param string $mode |
|
| 118 | + * @return resource |
|
| 119 | + */ |
|
| 120 | + public abstract function getStream($path, $mode); |
|
| 121 | + /** |
|
| 122 | + * add a folder and all its content |
|
| 123 | + * @param string $path |
|
| 124 | + * @param string $source |
|
| 125 | + * @return boolean|null |
|
| 126 | + */ |
|
| 127 | + public function addRecursive($path, $source) { |
|
| 128 | + $dh = opendir($source); |
|
| 129 | + if(is_resource($dh)) { |
|
| 130 | + $this->addFolder($path); |
|
| 131 | + while (($file = readdir($dh)) !== false) { |
|
| 132 | + if($file === '.' || $file === '..') { |
|
| 133 | + continue; |
|
| 134 | + } |
|
| 135 | + if(is_dir($source.'/'.$file)) { |
|
| 136 | + $this->addRecursive($path.'/'.$file, $source.'/'.$file); |
|
| 137 | + }else{ |
|
| 138 | + $this->addFile($path.'/'.$file, $source.'/'.$file); |
|
| 139 | + } |
|
| 140 | + } |
|
| 141 | + } |
|
| 142 | + } |
|
| 143 | 143 | } |
@@ -49,7 +49,7 @@ discard block |
||
| 49 | 49 | * @param string $source either a local file or string data |
| 50 | 50 | * @return bool |
| 51 | 51 | */ |
| 52 | - public abstract function addFile($path, $source=''); |
|
| 52 | + public abstract function addFile($path, $source = ''); |
|
| 53 | 53 | /** |
| 54 | 54 | * rename a file or folder in the archive |
| 55 | 55 | * @param string $source |
@@ -126,15 +126,15 @@ discard block |
||
| 126 | 126 | */ |
| 127 | 127 | public function addRecursive($path, $source) { |
| 128 | 128 | $dh = opendir($source); |
| 129 | - if(is_resource($dh)) { |
|
| 129 | + if (is_resource($dh)) { |
|
| 130 | 130 | $this->addFolder($path); |
| 131 | 131 | while (($file = readdir($dh)) !== false) { |
| 132 | - if($file === '.' || $file === '..') { |
|
| 132 | + if ($file === '.' || $file === '..') { |
|
| 133 | 133 | continue; |
| 134 | 134 | } |
| 135 | - if(is_dir($source.'/'.$file)) { |
|
| 135 | + if (is_dir($source.'/'.$file)) { |
|
| 136 | 136 | $this->addRecursive($path.'/'.$file, $source.'/'.$file); |
| 137 | - }else{ |
|
| 137 | + } else { |
|
| 138 | 138 | $this->addFile($path.'/'.$file, $source.'/'.$file); |
| 139 | 139 | } |
| 140 | 140 | } |
@@ -25,14 +25,14 @@ |
||
| 25 | 25 | namespace OC; |
| 26 | 26 | |
| 27 | 27 | class NaturalSort_DefaultCollator { |
| 28 | - public function compare($a, $b) { |
|
| 29 | - $result = strcasecmp($a, $b); |
|
| 30 | - if ($result === 0) { |
|
| 31 | - if ($a === $b) { |
|
| 32 | - return 0; |
|
| 33 | - } |
|
| 34 | - return ($a > $b) ? -1 : 1; |
|
| 35 | - } |
|
| 36 | - return ($result < 0) ? -1 : 1; |
|
| 37 | - } |
|
| 28 | + public function compare($a, $b) { |
|
| 29 | + $result = strcasecmp($a, $b); |
|
| 30 | + if ($result === 0) { |
|
| 31 | + if ($a === $b) { |
|
| 32 | + return 0; |
|
| 33 | + } |
|
| 34 | + return ($a > $b) ? -1 : 1; |
|
| 35 | + } |
|
| 36 | + return ($result < 0) ? -1 : 1; |
|
| 37 | + } |
|
| 38 | 38 | } |
@@ -61,7 +61,7 @@ |
||
| 61 | 61 | parent::__construct( 'core', 'layout.user' ); |
| 62 | 62 | if(in_array(\OC_App::getCurrentApp(), ['settings','admin', 'help']) !== false) { |
| 63 | 63 | $this->assign('bodyid', 'body-settings'); |
| 64 | - }else{ |
|
| 64 | + } else{ |
|
| 65 | 65 | $this->assign('bodyid', 'body-user'); |
| 66 | 66 | } |
| 67 | 67 | |
@@ -46,305 +46,305 @@ |
||
| 46 | 46 | |
| 47 | 47 | class TemplateLayout extends \OC_Template { |
| 48 | 48 | |
| 49 | - private static $versionHash = ''; |
|
| 50 | - |
|
| 51 | - /** |
|
| 52 | - * @var \OCP\IConfig |
|
| 53 | - */ |
|
| 54 | - private $config; |
|
| 55 | - |
|
| 56 | - /** |
|
| 57 | - * @param string $renderAs |
|
| 58 | - * @param string $appId application id |
|
| 59 | - */ |
|
| 60 | - public function __construct( $renderAs, $appId = '' ) { |
|
| 61 | - |
|
| 62 | - // yes - should be injected .... |
|
| 63 | - $this->config = \OC::$server->getConfig(); |
|
| 64 | - |
|
| 65 | - if(\OCP\Util::isIE()) { |
|
| 66 | - \OC_Util::addStyle('ie'); |
|
| 67 | - } |
|
| 68 | - |
|
| 69 | - // Decide which page we show |
|
| 70 | - if($renderAs === 'user') { |
|
| 71 | - parent::__construct( 'core', 'layout.user' ); |
|
| 72 | - if(in_array(\OC_App::getCurrentApp(), ['settings','admin', 'help']) !== false) { |
|
| 73 | - $this->assign('bodyid', 'body-settings'); |
|
| 74 | - }else{ |
|
| 75 | - $this->assign('bodyid', 'body-user'); |
|
| 76 | - } |
|
| 77 | - |
|
| 78 | - // Add navigation entry |
|
| 79 | - $this->assign( 'application', ''); |
|
| 80 | - $this->assign( 'appid', $appId ); |
|
| 81 | - $navigation = \OC::$server->getNavigationManager()->getAll(); |
|
| 82 | - $this->assign( 'navigation', $navigation); |
|
| 83 | - $settingsNavigation = \OC::$server->getNavigationManager()->getAll('settings'); |
|
| 84 | - $this->assign( 'settingsnavigation', $settingsNavigation); |
|
| 85 | - foreach($navigation as $entry) { |
|
| 86 | - if ($entry['active']) { |
|
| 87 | - $this->assign( 'application', $entry['name'] ); |
|
| 88 | - break; |
|
| 89 | - } |
|
| 90 | - } |
|
| 91 | - |
|
| 92 | - foreach($settingsNavigation as $entry) { |
|
| 93 | - if ($entry['active']) { |
|
| 94 | - $this->assign( 'application', $entry['name'] ); |
|
| 95 | - break; |
|
| 96 | - } |
|
| 97 | - } |
|
| 98 | - $userDisplayName = \OC_User::getDisplayName(); |
|
| 99 | - $this->assign('user_displayname', $userDisplayName); |
|
| 100 | - $this->assign('user_uid', \OC_User::getUser()); |
|
| 101 | - |
|
| 102 | - if (\OC_User::getUser() === false) { |
|
| 103 | - $this->assign('userAvatarSet', false); |
|
| 104 | - } else { |
|
| 105 | - $this->assign('userAvatarSet', \OC::$server->getAvatarManager()->getAvatar(\OC_User::getUser())->exists()); |
|
| 106 | - $this->assign('userAvatarVersion', $this->config->getUserValue(\OC_User::getUser(), 'avatar', 'version', 0)); |
|
| 107 | - } |
|
| 108 | - |
|
| 109 | - // check if app menu icons should be inverted |
|
| 110 | - try { |
|
| 111 | - /** @var \OCA\Theming\Util $util */ |
|
| 112 | - $util = \OC::$server->query(\OCA\Theming\Util::class); |
|
| 113 | - $this->assign('themingInvertMenu', $util->invertTextColor(\OC::$server->getThemingDefaults()->getColorPrimary())); |
|
| 114 | - } catch (\OCP\AppFramework\QueryException $e) { |
|
| 115 | - $this->assign('themingInvertMenu', false); |
|
| 116 | - } |
|
| 117 | - |
|
| 118 | - } else if ($renderAs === 'error') { |
|
| 119 | - parent::__construct('core', 'layout.guest', '', false); |
|
| 120 | - $this->assign('bodyid', 'body-login'); |
|
| 121 | - $this->assign('user_displayname', ''); |
|
| 122 | - $this->assign('user_uid', ''); |
|
| 123 | - } else if ($renderAs === 'guest') { |
|
| 124 | - parent::__construct('core', 'layout.guest'); |
|
| 125 | - \OC_Util::addStyle('guest'); |
|
| 126 | - $this->assign('bodyid', 'body-login'); |
|
| 127 | - |
|
| 128 | - $userDisplayName = \OC_User::getDisplayName(); |
|
| 129 | - $this->assign('user_displayname', $userDisplayName); |
|
| 130 | - $this->assign('user_uid', \OC_User::getUser()); |
|
| 131 | - } else if ($renderAs === 'public') { |
|
| 132 | - parent::__construct('core', 'layout.public'); |
|
| 133 | - $this->assign( 'appid', $appId ); |
|
| 134 | - $this->assign('bodyid', 'body-public'); |
|
| 135 | - $this->assign('showSimpleSignUpLink', $this->config->getSystemValue('simpleSignUpLink.shown', true) !== false); |
|
| 136 | - } else { |
|
| 137 | - parent::__construct('core', 'layout.base'); |
|
| 138 | - |
|
| 139 | - } |
|
| 140 | - // Send the language and the locale to our layouts |
|
| 141 | - $lang = \OC::$server->getL10NFactory()->findLanguage(); |
|
| 142 | - $locale = \OC::$server->getL10NFactory()->findLocale($lang); |
|
| 143 | - $localeLang = \OC::$server->getL10NFactory()->findLanguageFromLocale('lib', $locale); |
|
| 144 | - |
|
| 145 | - $lang = str_replace('_', '-', $lang); |
|
| 146 | - $this->assign('language', $lang); |
|
| 147 | - $this->assign('locale', $locale); |
|
| 148 | - |
|
| 149 | - if(\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
| 150 | - if (empty(self::$versionHash)) { |
|
| 151 | - $v = \OC_App::getAppVersions(); |
|
| 152 | - $v['core'] = implode('.', \OCP\Util::getVersion()); |
|
| 153 | - self::$versionHash = substr(md5(implode(',', $v)), 0, 8); |
|
| 154 | - } |
|
| 155 | - } else { |
|
| 156 | - self::$versionHash = md5('not installed'); |
|
| 157 | - } |
|
| 158 | - |
|
| 159 | - // Add the js files |
|
| 160 | - $jsFiles = self::findJavascriptFiles(\OC_Util::$scripts); |
|
| 161 | - $this->assign('jsfiles', array()); |
|
| 162 | - if ($this->config->getSystemValue('installed', false) && $renderAs != 'error') { |
|
| 163 | - if (\OC::$server->getContentSecurityPolicyNonceManager()->browserSupportsCspV3()) { |
|
| 164 | - $jsConfigHelper = new JSConfigHelper( |
|
| 165 | - \OC::$server->getL10N('lib', $localeLang ?: $lang), |
|
| 166 | - \OC::$server->query(Defaults::class), |
|
| 167 | - \OC::$server->getAppManager(), |
|
| 168 | - \OC::$server->getSession(), |
|
| 169 | - \OC::$server->getUserSession()->getUser(), |
|
| 170 | - $this->config, |
|
| 171 | - \OC::$server->getGroupManager(), |
|
| 172 | - \OC::$server->getIniWrapper(), |
|
| 173 | - \OC::$server->getURLGenerator(), |
|
| 174 | - \OC::$server->getCapabilitiesManager() |
|
| 175 | - ); |
|
| 176 | - $this->assign('inline_ocjs', $jsConfigHelper->getConfig()); |
|
| 177 | - } else { |
|
| 178 | - $this->append('jsfiles', \OC::$server->getURLGenerator()->linkToRoute('core.OCJS.getConfig', ['v' => self::$versionHash])); |
|
| 179 | - } |
|
| 180 | - } |
|
| 181 | - foreach($jsFiles as $info) { |
|
| 182 | - $web = $info[1]; |
|
| 183 | - $file = $info[2]; |
|
| 184 | - $this->append( 'jsfiles', $web.'/'.$file . $this->getVersionHashSuffix() ); |
|
| 185 | - } |
|
| 186 | - |
|
| 187 | - try { |
|
| 188 | - $pathInfo = \OC::$server->getRequest()->getPathInfo(); |
|
| 189 | - } catch (\Exception $e) { |
|
| 190 | - $pathInfo = ''; |
|
| 191 | - } |
|
| 192 | - |
|
| 193 | - // Do not initialise scss appdata until we have a fully installed instance |
|
| 194 | - // Do not load scss for update, errors, installation or login page |
|
| 195 | - if(\OC::$server->getSystemConfig()->getValue('installed', false) |
|
| 196 | - && !\OCP\Util::needUpgrade() |
|
| 197 | - && $pathInfo !== '' |
|
| 198 | - && !preg_match('/^\/login/', $pathInfo) |
|
| 199 | - && $renderAs !== 'error' |
|
| 200 | - ) { |
|
| 201 | - $cssFiles = self::findStylesheetFiles(\OC_Util::$styles); |
|
| 202 | - } else { |
|
| 203 | - // If we ignore the scss compiler, |
|
| 204 | - // we need to load the guest css fallback |
|
| 205 | - \OC_Util::addStyle('guest'); |
|
| 206 | - $cssFiles = self::findStylesheetFiles(\OC_Util::$styles, false); |
|
| 207 | - } |
|
| 208 | - |
|
| 209 | - $this->assign('cssfiles', array()); |
|
| 210 | - $this->assign('printcssfiles', []); |
|
| 211 | - $this->assign('versionHash', self::$versionHash); |
|
| 212 | - foreach($cssFiles as $info) { |
|
| 213 | - $web = $info[1]; |
|
| 214 | - $file = $info[2]; |
|
| 215 | - |
|
| 216 | - if (substr($file, -strlen('print.css')) === 'print.css') { |
|
| 217 | - $this->append( 'printcssfiles', $web.'/'.$file . $this->getVersionHashSuffix() ); |
|
| 218 | - } else { |
|
| 219 | - $suffix = $this->getVersionHashSuffix($web, $file); |
|
| 220 | - |
|
| 221 | - if (strpos($file, '?v=') == false) { |
|
| 222 | - $this->append( 'cssfiles', $web.'/'.$file . $suffix); |
|
| 223 | - } else { |
|
| 224 | - $this->append( 'cssfiles', $web.'/'.$file . '-' . substr($suffix, 3)); |
|
| 225 | - } |
|
| 226 | - |
|
| 227 | - } |
|
| 228 | - } |
|
| 229 | - |
|
| 230 | - /** @var InitialStateService $initialState */ |
|
| 231 | - $initialState = \OC::$server->query(InitialStateService::class); |
|
| 232 | - $this->assign('initialStates', $initialState->getInitialStates()); |
|
| 233 | - } |
|
| 234 | - |
|
| 235 | - /** |
|
| 236 | - * @param string $path |
|
| 237 | - * @param string $file |
|
| 238 | - * @return string |
|
| 239 | - */ |
|
| 240 | - protected function getVersionHashSuffix($path = false, $file = false) { |
|
| 241 | - if ($this->config->getSystemValue('debug', false)) { |
|
| 242 | - // allows chrome workspace mapping in debug mode |
|
| 243 | - return ""; |
|
| 244 | - } |
|
| 245 | - $themingSuffix = ''; |
|
| 246 | - $v = []; |
|
| 247 | - |
|
| 248 | - if ($this->config->getSystemValue('installed', false)) { |
|
| 249 | - if (\OC::$server->getAppManager()->isInstalled('theming')) { |
|
| 250 | - $themingSuffix = '-' . $this->config->getAppValue('theming', 'cachebuster', '0'); |
|
| 251 | - } |
|
| 252 | - $v = \OC_App::getAppVersions(); |
|
| 253 | - } |
|
| 254 | - |
|
| 255 | - // Try the webroot path for a match |
|
| 256 | - if ($path !== false && $path !== '') { |
|
| 257 | - $appName = $this->getAppNamefromPath($path); |
|
| 258 | - if(array_key_exists($appName, $v)) { |
|
| 259 | - $appVersion = $v[$appName]; |
|
| 260 | - return '?v=' . substr(md5($appVersion), 0, 8) . $themingSuffix; |
|
| 261 | - } |
|
| 262 | - } |
|
| 263 | - // fallback to the file path instead |
|
| 264 | - if ($file !== false && $file !== '') { |
|
| 265 | - $appName = $this->getAppNamefromPath($file); |
|
| 266 | - if(array_key_exists($appName, $v)) { |
|
| 267 | - $appVersion = $v[$appName]; |
|
| 268 | - return '?v=' . substr(md5($appVersion), 0, 8) . $themingSuffix; |
|
| 269 | - } |
|
| 270 | - } |
|
| 271 | - |
|
| 272 | - return '?v=' . self::$versionHash . $themingSuffix; |
|
| 273 | - } |
|
| 274 | - |
|
| 275 | - /** |
|
| 276 | - * @param array $styles |
|
| 277 | - * @return array |
|
| 278 | - */ |
|
| 279 | - static public function findStylesheetFiles($styles, $compileScss = true) { |
|
| 280 | - // Read the selected theme from the config file |
|
| 281 | - $theme = \OC_Util::getTheme(); |
|
| 282 | - |
|
| 283 | - if($compileScss) { |
|
| 284 | - $SCSSCacher = \OC::$server->query(SCSSCacher::class); |
|
| 285 | - } else { |
|
| 286 | - $SCSSCacher = null; |
|
| 287 | - } |
|
| 288 | - |
|
| 289 | - $locator = new \OC\Template\CSSResourceLocator( |
|
| 290 | - \OC::$server->getLogger(), |
|
| 291 | - $theme, |
|
| 292 | - array( \OC::$SERVERROOT => \OC::$WEBROOT ), |
|
| 293 | - array( \OC::$SERVERROOT => \OC::$WEBROOT ), |
|
| 294 | - $SCSSCacher |
|
| 295 | - ); |
|
| 296 | - $locator->find($styles); |
|
| 297 | - return $locator->getResources(); |
|
| 298 | - } |
|
| 299 | - |
|
| 300 | - /** |
|
| 301 | - * @param string $path |
|
| 302 | - * @return string|boolean |
|
| 303 | - */ |
|
| 304 | - public function getAppNamefromPath($path) { |
|
| 305 | - if ($path !== '' && is_string($path)) { |
|
| 306 | - $pathParts = explode('/', $path); |
|
| 307 | - if ($pathParts[0] === 'css') { |
|
| 308 | - // This is a scss request |
|
| 309 | - return $pathParts[1]; |
|
| 310 | - } |
|
| 311 | - return end($pathParts); |
|
| 312 | - } |
|
| 313 | - return false; |
|
| 314 | - |
|
| 315 | - } |
|
| 316 | - |
|
| 317 | - /** |
|
| 318 | - * @param array $scripts |
|
| 319 | - * @return array |
|
| 320 | - */ |
|
| 321 | - static public function findJavascriptFiles($scripts) { |
|
| 322 | - // Read the selected theme from the config file |
|
| 323 | - $theme = \OC_Util::getTheme(); |
|
| 324 | - |
|
| 325 | - $locator = new \OC\Template\JSResourceLocator( |
|
| 326 | - \OC::$server->getLogger(), |
|
| 327 | - $theme, |
|
| 328 | - array( \OC::$SERVERROOT => \OC::$WEBROOT ), |
|
| 329 | - array( \OC::$SERVERROOT => \OC::$WEBROOT ), |
|
| 330 | - \OC::$server->query(JSCombiner::class) |
|
| 331 | - ); |
|
| 332 | - $locator->find($scripts); |
|
| 333 | - return $locator->getResources(); |
|
| 334 | - } |
|
| 335 | - |
|
| 336 | - /** |
|
| 337 | - * Converts the absolute file path to a relative path from \OC::$SERVERROOT |
|
| 338 | - * @param string $filePath Absolute path |
|
| 339 | - * @return string Relative path |
|
| 340 | - * @throws \Exception If $filePath is not under \OC::$SERVERROOT |
|
| 341 | - */ |
|
| 342 | - public static function convertToRelativePath($filePath) { |
|
| 343 | - $relativePath = explode(\OC::$SERVERROOT, $filePath); |
|
| 344 | - if(count($relativePath) !== 2) { |
|
| 345 | - throw new \Exception('$filePath is not under the \OC::$SERVERROOT'); |
|
| 346 | - } |
|
| 347 | - |
|
| 348 | - return $relativePath[1]; |
|
| 349 | - } |
|
| 49 | + private static $versionHash = ''; |
|
| 50 | + |
|
| 51 | + /** |
|
| 52 | + * @var \OCP\IConfig |
|
| 53 | + */ |
|
| 54 | + private $config; |
|
| 55 | + |
|
| 56 | + /** |
|
| 57 | + * @param string $renderAs |
|
| 58 | + * @param string $appId application id |
|
| 59 | + */ |
|
| 60 | + public function __construct( $renderAs, $appId = '' ) { |
|
| 61 | + |
|
| 62 | + // yes - should be injected .... |
|
| 63 | + $this->config = \OC::$server->getConfig(); |
|
| 64 | + |
|
| 65 | + if(\OCP\Util::isIE()) { |
|
| 66 | + \OC_Util::addStyle('ie'); |
|
| 67 | + } |
|
| 68 | + |
|
| 69 | + // Decide which page we show |
|
| 70 | + if($renderAs === 'user') { |
|
| 71 | + parent::__construct( 'core', 'layout.user' ); |
|
| 72 | + if(in_array(\OC_App::getCurrentApp(), ['settings','admin', 'help']) !== false) { |
|
| 73 | + $this->assign('bodyid', 'body-settings'); |
|
| 74 | + }else{ |
|
| 75 | + $this->assign('bodyid', 'body-user'); |
|
| 76 | + } |
|
| 77 | + |
|
| 78 | + // Add navigation entry |
|
| 79 | + $this->assign( 'application', ''); |
|
| 80 | + $this->assign( 'appid', $appId ); |
|
| 81 | + $navigation = \OC::$server->getNavigationManager()->getAll(); |
|
| 82 | + $this->assign( 'navigation', $navigation); |
|
| 83 | + $settingsNavigation = \OC::$server->getNavigationManager()->getAll('settings'); |
|
| 84 | + $this->assign( 'settingsnavigation', $settingsNavigation); |
|
| 85 | + foreach($navigation as $entry) { |
|
| 86 | + if ($entry['active']) { |
|
| 87 | + $this->assign( 'application', $entry['name'] ); |
|
| 88 | + break; |
|
| 89 | + } |
|
| 90 | + } |
|
| 91 | + |
|
| 92 | + foreach($settingsNavigation as $entry) { |
|
| 93 | + if ($entry['active']) { |
|
| 94 | + $this->assign( 'application', $entry['name'] ); |
|
| 95 | + break; |
|
| 96 | + } |
|
| 97 | + } |
|
| 98 | + $userDisplayName = \OC_User::getDisplayName(); |
|
| 99 | + $this->assign('user_displayname', $userDisplayName); |
|
| 100 | + $this->assign('user_uid', \OC_User::getUser()); |
|
| 101 | + |
|
| 102 | + if (\OC_User::getUser() === false) { |
|
| 103 | + $this->assign('userAvatarSet', false); |
|
| 104 | + } else { |
|
| 105 | + $this->assign('userAvatarSet', \OC::$server->getAvatarManager()->getAvatar(\OC_User::getUser())->exists()); |
|
| 106 | + $this->assign('userAvatarVersion', $this->config->getUserValue(\OC_User::getUser(), 'avatar', 'version', 0)); |
|
| 107 | + } |
|
| 108 | + |
|
| 109 | + // check if app menu icons should be inverted |
|
| 110 | + try { |
|
| 111 | + /** @var \OCA\Theming\Util $util */ |
|
| 112 | + $util = \OC::$server->query(\OCA\Theming\Util::class); |
|
| 113 | + $this->assign('themingInvertMenu', $util->invertTextColor(\OC::$server->getThemingDefaults()->getColorPrimary())); |
|
| 114 | + } catch (\OCP\AppFramework\QueryException $e) { |
|
| 115 | + $this->assign('themingInvertMenu', false); |
|
| 116 | + } |
|
| 117 | + |
|
| 118 | + } else if ($renderAs === 'error') { |
|
| 119 | + parent::__construct('core', 'layout.guest', '', false); |
|
| 120 | + $this->assign('bodyid', 'body-login'); |
|
| 121 | + $this->assign('user_displayname', ''); |
|
| 122 | + $this->assign('user_uid', ''); |
|
| 123 | + } else if ($renderAs === 'guest') { |
|
| 124 | + parent::__construct('core', 'layout.guest'); |
|
| 125 | + \OC_Util::addStyle('guest'); |
|
| 126 | + $this->assign('bodyid', 'body-login'); |
|
| 127 | + |
|
| 128 | + $userDisplayName = \OC_User::getDisplayName(); |
|
| 129 | + $this->assign('user_displayname', $userDisplayName); |
|
| 130 | + $this->assign('user_uid', \OC_User::getUser()); |
|
| 131 | + } else if ($renderAs === 'public') { |
|
| 132 | + parent::__construct('core', 'layout.public'); |
|
| 133 | + $this->assign( 'appid', $appId ); |
|
| 134 | + $this->assign('bodyid', 'body-public'); |
|
| 135 | + $this->assign('showSimpleSignUpLink', $this->config->getSystemValue('simpleSignUpLink.shown', true) !== false); |
|
| 136 | + } else { |
|
| 137 | + parent::__construct('core', 'layout.base'); |
|
| 138 | + |
|
| 139 | + } |
|
| 140 | + // Send the language and the locale to our layouts |
|
| 141 | + $lang = \OC::$server->getL10NFactory()->findLanguage(); |
|
| 142 | + $locale = \OC::$server->getL10NFactory()->findLocale($lang); |
|
| 143 | + $localeLang = \OC::$server->getL10NFactory()->findLanguageFromLocale('lib', $locale); |
|
| 144 | + |
|
| 145 | + $lang = str_replace('_', '-', $lang); |
|
| 146 | + $this->assign('language', $lang); |
|
| 147 | + $this->assign('locale', $locale); |
|
| 148 | + |
|
| 149 | + if(\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
| 150 | + if (empty(self::$versionHash)) { |
|
| 151 | + $v = \OC_App::getAppVersions(); |
|
| 152 | + $v['core'] = implode('.', \OCP\Util::getVersion()); |
|
| 153 | + self::$versionHash = substr(md5(implode(',', $v)), 0, 8); |
|
| 154 | + } |
|
| 155 | + } else { |
|
| 156 | + self::$versionHash = md5('not installed'); |
|
| 157 | + } |
|
| 158 | + |
|
| 159 | + // Add the js files |
|
| 160 | + $jsFiles = self::findJavascriptFiles(\OC_Util::$scripts); |
|
| 161 | + $this->assign('jsfiles', array()); |
|
| 162 | + if ($this->config->getSystemValue('installed', false) && $renderAs != 'error') { |
|
| 163 | + if (\OC::$server->getContentSecurityPolicyNonceManager()->browserSupportsCspV3()) { |
|
| 164 | + $jsConfigHelper = new JSConfigHelper( |
|
| 165 | + \OC::$server->getL10N('lib', $localeLang ?: $lang), |
|
| 166 | + \OC::$server->query(Defaults::class), |
|
| 167 | + \OC::$server->getAppManager(), |
|
| 168 | + \OC::$server->getSession(), |
|
| 169 | + \OC::$server->getUserSession()->getUser(), |
|
| 170 | + $this->config, |
|
| 171 | + \OC::$server->getGroupManager(), |
|
| 172 | + \OC::$server->getIniWrapper(), |
|
| 173 | + \OC::$server->getURLGenerator(), |
|
| 174 | + \OC::$server->getCapabilitiesManager() |
|
| 175 | + ); |
|
| 176 | + $this->assign('inline_ocjs', $jsConfigHelper->getConfig()); |
|
| 177 | + } else { |
|
| 178 | + $this->append('jsfiles', \OC::$server->getURLGenerator()->linkToRoute('core.OCJS.getConfig', ['v' => self::$versionHash])); |
|
| 179 | + } |
|
| 180 | + } |
|
| 181 | + foreach($jsFiles as $info) { |
|
| 182 | + $web = $info[1]; |
|
| 183 | + $file = $info[2]; |
|
| 184 | + $this->append( 'jsfiles', $web.'/'.$file . $this->getVersionHashSuffix() ); |
|
| 185 | + } |
|
| 186 | + |
|
| 187 | + try { |
|
| 188 | + $pathInfo = \OC::$server->getRequest()->getPathInfo(); |
|
| 189 | + } catch (\Exception $e) { |
|
| 190 | + $pathInfo = ''; |
|
| 191 | + } |
|
| 192 | + |
|
| 193 | + // Do not initialise scss appdata until we have a fully installed instance |
|
| 194 | + // Do not load scss for update, errors, installation or login page |
|
| 195 | + if(\OC::$server->getSystemConfig()->getValue('installed', false) |
|
| 196 | + && !\OCP\Util::needUpgrade() |
|
| 197 | + && $pathInfo !== '' |
|
| 198 | + && !preg_match('/^\/login/', $pathInfo) |
|
| 199 | + && $renderAs !== 'error' |
|
| 200 | + ) { |
|
| 201 | + $cssFiles = self::findStylesheetFiles(\OC_Util::$styles); |
|
| 202 | + } else { |
|
| 203 | + // If we ignore the scss compiler, |
|
| 204 | + // we need to load the guest css fallback |
|
| 205 | + \OC_Util::addStyle('guest'); |
|
| 206 | + $cssFiles = self::findStylesheetFiles(\OC_Util::$styles, false); |
|
| 207 | + } |
|
| 208 | + |
|
| 209 | + $this->assign('cssfiles', array()); |
|
| 210 | + $this->assign('printcssfiles', []); |
|
| 211 | + $this->assign('versionHash', self::$versionHash); |
|
| 212 | + foreach($cssFiles as $info) { |
|
| 213 | + $web = $info[1]; |
|
| 214 | + $file = $info[2]; |
|
| 215 | + |
|
| 216 | + if (substr($file, -strlen('print.css')) === 'print.css') { |
|
| 217 | + $this->append( 'printcssfiles', $web.'/'.$file . $this->getVersionHashSuffix() ); |
|
| 218 | + } else { |
|
| 219 | + $suffix = $this->getVersionHashSuffix($web, $file); |
|
| 220 | + |
|
| 221 | + if (strpos($file, '?v=') == false) { |
|
| 222 | + $this->append( 'cssfiles', $web.'/'.$file . $suffix); |
|
| 223 | + } else { |
|
| 224 | + $this->append( 'cssfiles', $web.'/'.$file . '-' . substr($suffix, 3)); |
|
| 225 | + } |
|
| 226 | + |
|
| 227 | + } |
|
| 228 | + } |
|
| 229 | + |
|
| 230 | + /** @var InitialStateService $initialState */ |
|
| 231 | + $initialState = \OC::$server->query(InitialStateService::class); |
|
| 232 | + $this->assign('initialStates', $initialState->getInitialStates()); |
|
| 233 | + } |
|
| 234 | + |
|
| 235 | + /** |
|
| 236 | + * @param string $path |
|
| 237 | + * @param string $file |
|
| 238 | + * @return string |
|
| 239 | + */ |
|
| 240 | + protected function getVersionHashSuffix($path = false, $file = false) { |
|
| 241 | + if ($this->config->getSystemValue('debug', false)) { |
|
| 242 | + // allows chrome workspace mapping in debug mode |
|
| 243 | + return ""; |
|
| 244 | + } |
|
| 245 | + $themingSuffix = ''; |
|
| 246 | + $v = []; |
|
| 247 | + |
|
| 248 | + if ($this->config->getSystemValue('installed', false)) { |
|
| 249 | + if (\OC::$server->getAppManager()->isInstalled('theming')) { |
|
| 250 | + $themingSuffix = '-' . $this->config->getAppValue('theming', 'cachebuster', '0'); |
|
| 251 | + } |
|
| 252 | + $v = \OC_App::getAppVersions(); |
|
| 253 | + } |
|
| 254 | + |
|
| 255 | + // Try the webroot path for a match |
|
| 256 | + if ($path !== false && $path !== '') { |
|
| 257 | + $appName = $this->getAppNamefromPath($path); |
|
| 258 | + if(array_key_exists($appName, $v)) { |
|
| 259 | + $appVersion = $v[$appName]; |
|
| 260 | + return '?v=' . substr(md5($appVersion), 0, 8) . $themingSuffix; |
|
| 261 | + } |
|
| 262 | + } |
|
| 263 | + // fallback to the file path instead |
|
| 264 | + if ($file !== false && $file !== '') { |
|
| 265 | + $appName = $this->getAppNamefromPath($file); |
|
| 266 | + if(array_key_exists($appName, $v)) { |
|
| 267 | + $appVersion = $v[$appName]; |
|
| 268 | + return '?v=' . substr(md5($appVersion), 0, 8) . $themingSuffix; |
|
| 269 | + } |
|
| 270 | + } |
|
| 271 | + |
|
| 272 | + return '?v=' . self::$versionHash . $themingSuffix; |
|
| 273 | + } |
|
| 274 | + |
|
| 275 | + /** |
|
| 276 | + * @param array $styles |
|
| 277 | + * @return array |
|
| 278 | + */ |
|
| 279 | + static public function findStylesheetFiles($styles, $compileScss = true) { |
|
| 280 | + // Read the selected theme from the config file |
|
| 281 | + $theme = \OC_Util::getTheme(); |
|
| 282 | + |
|
| 283 | + if($compileScss) { |
|
| 284 | + $SCSSCacher = \OC::$server->query(SCSSCacher::class); |
|
| 285 | + } else { |
|
| 286 | + $SCSSCacher = null; |
|
| 287 | + } |
|
| 288 | + |
|
| 289 | + $locator = new \OC\Template\CSSResourceLocator( |
|
| 290 | + \OC::$server->getLogger(), |
|
| 291 | + $theme, |
|
| 292 | + array( \OC::$SERVERROOT => \OC::$WEBROOT ), |
|
| 293 | + array( \OC::$SERVERROOT => \OC::$WEBROOT ), |
|
| 294 | + $SCSSCacher |
|
| 295 | + ); |
|
| 296 | + $locator->find($styles); |
|
| 297 | + return $locator->getResources(); |
|
| 298 | + } |
|
| 299 | + |
|
| 300 | + /** |
|
| 301 | + * @param string $path |
|
| 302 | + * @return string|boolean |
|
| 303 | + */ |
|
| 304 | + public function getAppNamefromPath($path) { |
|
| 305 | + if ($path !== '' && is_string($path)) { |
|
| 306 | + $pathParts = explode('/', $path); |
|
| 307 | + if ($pathParts[0] === 'css') { |
|
| 308 | + // This is a scss request |
|
| 309 | + return $pathParts[1]; |
|
| 310 | + } |
|
| 311 | + return end($pathParts); |
|
| 312 | + } |
|
| 313 | + return false; |
|
| 314 | + |
|
| 315 | + } |
|
| 316 | + |
|
| 317 | + /** |
|
| 318 | + * @param array $scripts |
|
| 319 | + * @return array |
|
| 320 | + */ |
|
| 321 | + static public function findJavascriptFiles($scripts) { |
|
| 322 | + // Read the selected theme from the config file |
|
| 323 | + $theme = \OC_Util::getTheme(); |
|
| 324 | + |
|
| 325 | + $locator = new \OC\Template\JSResourceLocator( |
|
| 326 | + \OC::$server->getLogger(), |
|
| 327 | + $theme, |
|
| 328 | + array( \OC::$SERVERROOT => \OC::$WEBROOT ), |
|
| 329 | + array( \OC::$SERVERROOT => \OC::$WEBROOT ), |
|
| 330 | + \OC::$server->query(JSCombiner::class) |
|
| 331 | + ); |
|
| 332 | + $locator->find($scripts); |
|
| 333 | + return $locator->getResources(); |
|
| 334 | + } |
|
| 335 | + |
|
| 336 | + /** |
|
| 337 | + * Converts the absolute file path to a relative path from \OC::$SERVERROOT |
|
| 338 | + * @param string $filePath Absolute path |
|
| 339 | + * @return string Relative path |
|
| 340 | + * @throws \Exception If $filePath is not under \OC::$SERVERROOT |
|
| 341 | + */ |
|
| 342 | + public static function convertToRelativePath($filePath) { |
|
| 343 | + $relativePath = explode(\OC::$SERVERROOT, $filePath); |
|
| 344 | + if(count($relativePath) !== 2) { |
|
| 345 | + throw new \Exception('$filePath is not under the \OC::$SERVERROOT'); |
|
| 346 | + } |
|
| 347 | + |
|
| 348 | + return $relativePath[1]; |
|
| 349 | + } |
|
| 350 | 350 | } |
@@ -57,41 +57,41 @@ discard block |
||
| 57 | 57 | * @param string $renderAs |
| 58 | 58 | * @param string $appId application id |
| 59 | 59 | */ |
| 60 | - public function __construct( $renderAs, $appId = '' ) { |
|
| 60 | + public function __construct($renderAs, $appId = '') { |
|
| 61 | 61 | |
| 62 | 62 | // yes - should be injected .... |
| 63 | 63 | $this->config = \OC::$server->getConfig(); |
| 64 | 64 | |
| 65 | - if(\OCP\Util::isIE()) { |
|
| 65 | + if (\OCP\Util::isIE()) { |
|
| 66 | 66 | \OC_Util::addStyle('ie'); |
| 67 | 67 | } |
| 68 | 68 | |
| 69 | 69 | // Decide which page we show |
| 70 | - if($renderAs === 'user') { |
|
| 71 | - parent::__construct( 'core', 'layout.user' ); |
|
| 72 | - if(in_array(\OC_App::getCurrentApp(), ['settings','admin', 'help']) !== false) { |
|
| 70 | + if ($renderAs === 'user') { |
|
| 71 | + parent::__construct('core', 'layout.user'); |
|
| 72 | + if (in_array(\OC_App::getCurrentApp(), ['settings', 'admin', 'help']) !== false) { |
|
| 73 | 73 | $this->assign('bodyid', 'body-settings'); |
| 74 | - }else{ |
|
| 74 | + } else { |
|
| 75 | 75 | $this->assign('bodyid', 'body-user'); |
| 76 | 76 | } |
| 77 | 77 | |
| 78 | 78 | // Add navigation entry |
| 79 | - $this->assign( 'application', ''); |
|
| 80 | - $this->assign( 'appid', $appId ); |
|
| 79 | + $this->assign('application', ''); |
|
| 80 | + $this->assign('appid', $appId); |
|
| 81 | 81 | $navigation = \OC::$server->getNavigationManager()->getAll(); |
| 82 | - $this->assign( 'navigation', $navigation); |
|
| 82 | + $this->assign('navigation', $navigation); |
|
| 83 | 83 | $settingsNavigation = \OC::$server->getNavigationManager()->getAll('settings'); |
| 84 | - $this->assign( 'settingsnavigation', $settingsNavigation); |
|
| 85 | - foreach($navigation as $entry) { |
|
| 84 | + $this->assign('settingsnavigation', $settingsNavigation); |
|
| 85 | + foreach ($navigation as $entry) { |
|
| 86 | 86 | if ($entry['active']) { |
| 87 | - $this->assign( 'application', $entry['name'] ); |
|
| 87 | + $this->assign('application', $entry['name']); |
|
| 88 | 88 | break; |
| 89 | 89 | } |
| 90 | 90 | } |
| 91 | 91 | |
| 92 | - foreach($settingsNavigation as $entry) { |
|
| 92 | + foreach ($settingsNavigation as $entry) { |
|
| 93 | 93 | if ($entry['active']) { |
| 94 | - $this->assign( 'application', $entry['name'] ); |
|
| 94 | + $this->assign('application', $entry['name']); |
|
| 95 | 95 | break; |
| 96 | 96 | } |
| 97 | 97 | } |
@@ -130,7 +130,7 @@ discard block |
||
| 130 | 130 | $this->assign('user_uid', \OC_User::getUser()); |
| 131 | 131 | } else if ($renderAs === 'public') { |
| 132 | 132 | parent::__construct('core', 'layout.public'); |
| 133 | - $this->assign( 'appid', $appId ); |
|
| 133 | + $this->assign('appid', $appId); |
|
| 134 | 134 | $this->assign('bodyid', 'body-public'); |
| 135 | 135 | $this->assign('showSimpleSignUpLink', $this->config->getSystemValue('simpleSignUpLink.shown', true) !== false); |
| 136 | 136 | } else { |
@@ -146,7 +146,7 @@ discard block |
||
| 146 | 146 | $this->assign('language', $lang); |
| 147 | 147 | $this->assign('locale', $locale); |
| 148 | 148 | |
| 149 | - if(\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
| 149 | + if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
| 150 | 150 | if (empty(self::$versionHash)) { |
| 151 | 151 | $v = \OC_App::getAppVersions(); |
| 152 | 152 | $v['core'] = implode('.', \OCP\Util::getVersion()); |
@@ -178,10 +178,10 @@ discard block |
||
| 178 | 178 | $this->append('jsfiles', \OC::$server->getURLGenerator()->linkToRoute('core.OCJS.getConfig', ['v' => self::$versionHash])); |
| 179 | 179 | } |
| 180 | 180 | } |
| 181 | - foreach($jsFiles as $info) { |
|
| 181 | + foreach ($jsFiles as $info) { |
|
| 182 | 182 | $web = $info[1]; |
| 183 | 183 | $file = $info[2]; |
| 184 | - $this->append( 'jsfiles', $web.'/'.$file . $this->getVersionHashSuffix() ); |
|
| 184 | + $this->append('jsfiles', $web.'/'.$file.$this->getVersionHashSuffix()); |
|
| 185 | 185 | } |
| 186 | 186 | |
| 187 | 187 | try { |
@@ -192,7 +192,7 @@ discard block |
||
| 192 | 192 | |
| 193 | 193 | // Do not initialise scss appdata until we have a fully installed instance |
| 194 | 194 | // Do not load scss for update, errors, installation or login page |
| 195 | - if(\OC::$server->getSystemConfig()->getValue('installed', false) |
|
| 195 | + if (\OC::$server->getSystemConfig()->getValue('installed', false) |
|
| 196 | 196 | && !\OCP\Util::needUpgrade() |
| 197 | 197 | && $pathInfo !== '' |
| 198 | 198 | && !preg_match('/^\/login/', $pathInfo) |
@@ -209,19 +209,19 @@ discard block |
||
| 209 | 209 | $this->assign('cssfiles', array()); |
| 210 | 210 | $this->assign('printcssfiles', []); |
| 211 | 211 | $this->assign('versionHash', self::$versionHash); |
| 212 | - foreach($cssFiles as $info) { |
|
| 212 | + foreach ($cssFiles as $info) { |
|
| 213 | 213 | $web = $info[1]; |
| 214 | 214 | $file = $info[2]; |
| 215 | 215 | |
| 216 | 216 | if (substr($file, -strlen('print.css')) === 'print.css') { |
| 217 | - $this->append( 'printcssfiles', $web.'/'.$file . $this->getVersionHashSuffix() ); |
|
| 217 | + $this->append('printcssfiles', $web.'/'.$file.$this->getVersionHashSuffix()); |
|
| 218 | 218 | } else { |
| 219 | 219 | $suffix = $this->getVersionHashSuffix($web, $file); |
| 220 | 220 | |
| 221 | 221 | if (strpos($file, '?v=') == false) { |
| 222 | - $this->append( 'cssfiles', $web.'/'.$file . $suffix); |
|
| 222 | + $this->append('cssfiles', $web.'/'.$file.$suffix); |
|
| 223 | 223 | } else { |
| 224 | - $this->append( 'cssfiles', $web.'/'.$file . '-' . substr($suffix, 3)); |
|
| 224 | + $this->append('cssfiles', $web.'/'.$file.'-'.substr($suffix, 3)); |
|
| 225 | 225 | } |
| 226 | 226 | |
| 227 | 227 | } |
@@ -247,7 +247,7 @@ discard block |
||
| 247 | 247 | |
| 248 | 248 | if ($this->config->getSystemValue('installed', false)) { |
| 249 | 249 | if (\OC::$server->getAppManager()->isInstalled('theming')) { |
| 250 | - $themingSuffix = '-' . $this->config->getAppValue('theming', 'cachebuster', '0'); |
|
| 250 | + $themingSuffix = '-'.$this->config->getAppValue('theming', 'cachebuster', '0'); |
|
| 251 | 251 | } |
| 252 | 252 | $v = \OC_App::getAppVersions(); |
| 253 | 253 | } |
@@ -255,21 +255,21 @@ discard block |
||
| 255 | 255 | // Try the webroot path for a match |
| 256 | 256 | if ($path !== false && $path !== '') { |
| 257 | 257 | $appName = $this->getAppNamefromPath($path); |
| 258 | - if(array_key_exists($appName, $v)) { |
|
| 258 | + if (array_key_exists($appName, $v)) { |
|
| 259 | 259 | $appVersion = $v[$appName]; |
| 260 | - return '?v=' . substr(md5($appVersion), 0, 8) . $themingSuffix; |
|
| 260 | + return '?v='.substr(md5($appVersion), 0, 8).$themingSuffix; |
|
| 261 | 261 | } |
| 262 | 262 | } |
| 263 | 263 | // fallback to the file path instead |
| 264 | 264 | if ($file !== false && $file !== '') { |
| 265 | 265 | $appName = $this->getAppNamefromPath($file); |
| 266 | - if(array_key_exists($appName, $v)) { |
|
| 266 | + if (array_key_exists($appName, $v)) { |
|
| 267 | 267 | $appVersion = $v[$appName]; |
| 268 | - return '?v=' . substr(md5($appVersion), 0, 8) . $themingSuffix; |
|
| 268 | + return '?v='.substr(md5($appVersion), 0, 8).$themingSuffix; |
|
| 269 | 269 | } |
| 270 | 270 | } |
| 271 | 271 | |
| 272 | - return '?v=' . self::$versionHash . $themingSuffix; |
|
| 272 | + return '?v='.self::$versionHash.$themingSuffix; |
|
| 273 | 273 | } |
| 274 | 274 | |
| 275 | 275 | /** |
@@ -280,7 +280,7 @@ discard block |
||
| 280 | 280 | // Read the selected theme from the config file |
| 281 | 281 | $theme = \OC_Util::getTheme(); |
| 282 | 282 | |
| 283 | - if($compileScss) { |
|
| 283 | + if ($compileScss) { |
|
| 284 | 284 | $SCSSCacher = \OC::$server->query(SCSSCacher::class); |
| 285 | 285 | } else { |
| 286 | 286 | $SCSSCacher = null; |
@@ -289,8 +289,8 @@ discard block |
||
| 289 | 289 | $locator = new \OC\Template\CSSResourceLocator( |
| 290 | 290 | \OC::$server->getLogger(), |
| 291 | 291 | $theme, |
| 292 | - array( \OC::$SERVERROOT => \OC::$WEBROOT ), |
|
| 293 | - array( \OC::$SERVERROOT => \OC::$WEBROOT ), |
|
| 292 | + array(\OC::$SERVERROOT => \OC::$WEBROOT), |
|
| 293 | + array(\OC::$SERVERROOT => \OC::$WEBROOT), |
|
| 294 | 294 | $SCSSCacher |
| 295 | 295 | ); |
| 296 | 296 | $locator->find($styles); |
@@ -325,8 +325,8 @@ discard block |
||
| 325 | 325 | $locator = new \OC\Template\JSResourceLocator( |
| 326 | 326 | \OC::$server->getLogger(), |
| 327 | 327 | $theme, |
| 328 | - array( \OC::$SERVERROOT => \OC::$WEBROOT ), |
|
| 329 | - array( \OC::$SERVERROOT => \OC::$WEBROOT ), |
|
| 328 | + array(\OC::$SERVERROOT => \OC::$WEBROOT), |
|
| 329 | + array(\OC::$SERVERROOT => \OC::$WEBROOT), |
|
| 330 | 330 | \OC::$server->query(JSCombiner::class) |
| 331 | 331 | ); |
| 332 | 332 | $locator->find($scripts); |
@@ -341,7 +341,7 @@ discard block |
||
| 341 | 341 | */ |
| 342 | 342 | public static function convertToRelativePath($filePath) { |
| 343 | 343 | $relativePath = explode(\OC::$SERVERROOT, $filePath); |
| 344 | - if(count($relativePath) !== 2) { |
|
| 344 | + if (count($relativePath) !== 2) { |
|
| 345 | 345 | throw new \Exception('$filePath is not under the \OC::$SERVERROOT'); |
| 346 | 346 | } |
| 347 | 347 | |
@@ -57,7 +57,7 @@ discard block |
||
| 57 | 57 | */ |
| 58 | 58 | public function execute($jobList, ILogger $logger = null) { |
| 59 | 59 | // add an interval of 15 mins |
| 60 | - $this->setInterval(15*60); |
|
| 60 | + $this->setInterval(15 * 60); |
|
| 61 | 61 | |
| 62 | 62 | $this->jobList = $jobList; |
| 63 | 63 | $this->logger = $logger; |
@@ -90,7 +90,7 @@ discard block |
||
| 90 | 90 | try { |
| 91 | 91 | $repair->addStep($step); |
| 92 | 92 | } catch (\Exception $ex) { |
| 93 | - $this->logger->logException($ex,[ |
|
| 93 | + $this->logger->logException($ex, [ |
|
| 94 | 94 | 'app' => 'migration' |
| 95 | 95 | ]); |
| 96 | 96 | |
@@ -38,85 +38,85 @@ |
||
| 38 | 38 | */ |
| 39 | 39 | class BackgroundRepair extends TimedJob { |
| 40 | 40 | |
| 41 | - /** @var IJobList */ |
|
| 42 | - private $jobList; |
|
| 41 | + /** @var IJobList */ |
|
| 42 | + private $jobList; |
|
| 43 | 43 | |
| 44 | - /** @var ILogger */ |
|
| 45 | - private $logger; |
|
| 44 | + /** @var ILogger */ |
|
| 45 | + private $logger; |
|
| 46 | 46 | |
| 47 | - /** @var EventDispatcherInterface */ |
|
| 48 | - private $dispatcher; |
|
| 47 | + /** @var EventDispatcherInterface */ |
|
| 48 | + private $dispatcher; |
|
| 49 | 49 | |
| 50 | - /** |
|
| 51 | - * @param EventDispatcherInterface $dispatcher |
|
| 52 | - */ |
|
| 53 | - public function setDispatcher(EventDispatcherInterface $dispatcher): void { |
|
| 54 | - $this->dispatcher = $dispatcher; |
|
| 55 | - } |
|
| 50 | + /** |
|
| 51 | + * @param EventDispatcherInterface $dispatcher |
|
| 52 | + */ |
|
| 53 | + public function setDispatcher(EventDispatcherInterface $dispatcher): void { |
|
| 54 | + $this->dispatcher = $dispatcher; |
|
| 55 | + } |
|
| 56 | 56 | |
| 57 | - /** |
|
| 58 | - * run the job, then remove it from the job list |
|
| 59 | - * |
|
| 60 | - * @param JobList $jobList |
|
| 61 | - * @param ILogger|null $logger |
|
| 62 | - */ |
|
| 63 | - public function execute($jobList, ILogger $logger = null) { |
|
| 64 | - // add an interval of 15 mins |
|
| 65 | - $this->setInterval(15*60); |
|
| 57 | + /** |
|
| 58 | + * run the job, then remove it from the job list |
|
| 59 | + * |
|
| 60 | + * @param JobList $jobList |
|
| 61 | + * @param ILogger|null $logger |
|
| 62 | + */ |
|
| 63 | + public function execute($jobList, ILogger $logger = null) { |
|
| 64 | + // add an interval of 15 mins |
|
| 65 | + $this->setInterval(15*60); |
|
| 66 | 66 | |
| 67 | - $this->jobList = $jobList; |
|
| 68 | - $this->logger = $logger; |
|
| 69 | - parent::execute($jobList, $logger); |
|
| 70 | - } |
|
| 67 | + $this->jobList = $jobList; |
|
| 68 | + $this->logger = $logger; |
|
| 69 | + parent::execute($jobList, $logger); |
|
| 70 | + } |
|
| 71 | 71 | |
| 72 | - /** |
|
| 73 | - * @param array $argument |
|
| 74 | - * @throws \Exception |
|
| 75 | - * @throws \OC\NeedsUpdateException |
|
| 76 | - */ |
|
| 77 | - protected function run($argument) { |
|
| 78 | - if (!isset($argument['app']) || !isset($argument['step'])) { |
|
| 79 | - // remove the job - we can never execute it |
|
| 80 | - $this->jobList->remove($this, $this->argument); |
|
| 81 | - return; |
|
| 82 | - } |
|
| 83 | - $app = $argument['app']; |
|
| 72 | + /** |
|
| 73 | + * @param array $argument |
|
| 74 | + * @throws \Exception |
|
| 75 | + * @throws \OC\NeedsUpdateException |
|
| 76 | + */ |
|
| 77 | + protected function run($argument) { |
|
| 78 | + if (!isset($argument['app']) || !isset($argument['step'])) { |
|
| 79 | + // remove the job - we can never execute it |
|
| 80 | + $this->jobList->remove($this, $this->argument); |
|
| 81 | + return; |
|
| 82 | + } |
|
| 83 | + $app = $argument['app']; |
|
| 84 | 84 | |
| 85 | - try { |
|
| 86 | - $this->loadApp($app); |
|
| 87 | - } catch (NeedsUpdateException $ex) { |
|
| 88 | - // as long as the app is not yet done with it's offline migration |
|
| 89 | - // we better not start with the live migration |
|
| 90 | - return; |
|
| 91 | - } |
|
| 85 | + try { |
|
| 86 | + $this->loadApp($app); |
|
| 87 | + } catch (NeedsUpdateException $ex) { |
|
| 88 | + // as long as the app is not yet done with it's offline migration |
|
| 89 | + // we better not start with the live migration |
|
| 90 | + return; |
|
| 91 | + } |
|
| 92 | 92 | |
| 93 | - $step = $argument['step']; |
|
| 94 | - $repair = new Repair([], $this->dispatcher); |
|
| 95 | - try { |
|
| 96 | - $repair->addStep($step); |
|
| 97 | - } catch (\Exception $ex) { |
|
| 98 | - $this->logger->logException($ex,[ |
|
| 99 | - 'app' => 'migration' |
|
| 100 | - ]); |
|
| 93 | + $step = $argument['step']; |
|
| 94 | + $repair = new Repair([], $this->dispatcher); |
|
| 95 | + try { |
|
| 96 | + $repair->addStep($step); |
|
| 97 | + } catch (\Exception $ex) { |
|
| 98 | + $this->logger->logException($ex,[ |
|
| 99 | + 'app' => 'migration' |
|
| 100 | + ]); |
|
| 101 | 101 | |
| 102 | - // remove the job - we can never execute it |
|
| 103 | - $this->jobList->remove($this, $this->argument); |
|
| 104 | - return; |
|
| 105 | - } |
|
| 102 | + // remove the job - we can never execute it |
|
| 103 | + $this->jobList->remove($this, $this->argument); |
|
| 104 | + return; |
|
| 105 | + } |
|
| 106 | 106 | |
| 107 | - // execute the repair step |
|
| 108 | - $repair->run(); |
|
| 107 | + // execute the repair step |
|
| 108 | + $repair->run(); |
|
| 109 | 109 | |
| 110 | - // remove the job once executed successfully |
|
| 111 | - $this->jobList->remove($this, $this->argument); |
|
| 112 | - } |
|
| 110 | + // remove the job once executed successfully |
|
| 111 | + $this->jobList->remove($this, $this->argument); |
|
| 112 | + } |
|
| 113 | 113 | |
| 114 | - /** |
|
| 115 | - * @codeCoverageIgnore |
|
| 116 | - * @param $app |
|
| 117 | - * @throws NeedsUpdateException |
|
| 118 | - */ |
|
| 119 | - protected function loadApp($app) { |
|
| 120 | - OC_App::loadApp($app); |
|
| 121 | - } |
|
| 114 | + /** |
|
| 115 | + * @codeCoverageIgnore |
|
| 116 | + * @param $app |
|
| 117 | + * @throws NeedsUpdateException |
|
| 118 | + */ |
|
| 119 | + protected function loadApp($app) { |
|
| 120 | + OC_App::loadApp($app); |
|
| 121 | + } |
|
| 122 | 122 | } |
@@ -55,7 +55,7 @@ |
||
| 55 | 55 | if ($command instanceof ICommand) { |
| 56 | 56 | // ensure the command can be serialized |
| 57 | 57 | $serialized = serialize($command); |
| 58 | - if(strlen($serialized) > 4000) { |
|
| 58 | + if (strlen($serialized) > 4000) { |
|
| 59 | 59 | throw new \InvalidArgumentException('Trying to push a command which serialized form can not be stored in the database (>4000 character)'); |
| 60 | 60 | } |
| 61 | 61 | $unserialized = unserialize($serialized); |
@@ -26,48 +26,48 @@ |
||
| 26 | 26 | use OCP\Command\ICommand; |
| 27 | 27 | |
| 28 | 28 | class QueueBus implements IBus { |
| 29 | - /** |
|
| 30 | - * @var ICommand[]|callable[] |
|
| 31 | - */ |
|
| 32 | - private $queue = []; |
|
| 29 | + /** |
|
| 30 | + * @var ICommand[]|callable[] |
|
| 31 | + */ |
|
| 32 | + private $queue = []; |
|
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * Schedule a command to be fired |
|
| 36 | - * |
|
| 37 | - * @param \OCP\Command\ICommand | callable $command |
|
| 38 | - */ |
|
| 39 | - public function push($command) { |
|
| 40 | - $this->queue[] = $command; |
|
| 41 | - } |
|
| 34 | + /** |
|
| 35 | + * Schedule a command to be fired |
|
| 36 | + * |
|
| 37 | + * @param \OCP\Command\ICommand | callable $command |
|
| 38 | + */ |
|
| 39 | + public function push($command) { |
|
| 40 | + $this->queue[] = $command; |
|
| 41 | + } |
|
| 42 | 42 | |
| 43 | - /** |
|
| 44 | - * Require all commands using a trait to be run synchronous |
|
| 45 | - * |
|
| 46 | - * @param string $trait |
|
| 47 | - */ |
|
| 48 | - public function requireSync($trait) { |
|
| 49 | - } |
|
| 43 | + /** |
|
| 44 | + * Require all commands using a trait to be run synchronous |
|
| 45 | + * |
|
| 46 | + * @param string $trait |
|
| 47 | + */ |
|
| 48 | + public function requireSync($trait) { |
|
| 49 | + } |
|
| 50 | 50 | |
| 51 | - /** |
|
| 52 | - * @param \OCP\Command\ICommand | callable $command |
|
| 53 | - */ |
|
| 54 | - private function runCommand($command) { |
|
| 55 | - if ($command instanceof ICommand) { |
|
| 56 | - // ensure the command can be serialized |
|
| 57 | - $serialized = serialize($command); |
|
| 58 | - if(strlen($serialized) > 4000) { |
|
| 59 | - throw new \InvalidArgumentException('Trying to push a command which serialized form can not be stored in the database (>4000 character)'); |
|
| 60 | - } |
|
| 61 | - $unserialized = unserialize($serialized); |
|
| 62 | - $unserialized->handle(); |
|
| 63 | - } else { |
|
| 64 | - $command(); |
|
| 65 | - } |
|
| 66 | - } |
|
| 51 | + /** |
|
| 52 | + * @param \OCP\Command\ICommand | callable $command |
|
| 53 | + */ |
|
| 54 | + private function runCommand($command) { |
|
| 55 | + if ($command instanceof ICommand) { |
|
| 56 | + // ensure the command can be serialized |
|
| 57 | + $serialized = serialize($command); |
|
| 58 | + if(strlen($serialized) > 4000) { |
|
| 59 | + throw new \InvalidArgumentException('Trying to push a command which serialized form can not be stored in the database (>4000 character)'); |
|
| 60 | + } |
|
| 61 | + $unserialized = unserialize($serialized); |
|
| 62 | + $unserialized->handle(); |
|
| 63 | + } else { |
|
| 64 | + $command(); |
|
| 65 | + } |
|
| 66 | + } |
|
| 67 | 67 | |
| 68 | - public function run() { |
|
| 69 | - while ($command = array_shift($this->queue)) { |
|
| 70 | - $this->runCommand($command); |
|
| 71 | - } |
|
| 72 | - } |
|
| 68 | + public function run() { |
|
| 69 | + while ($command = array_shift($this->queue)) { |
|
| 70 | + $this->runCommand($command); |
|
| 71 | + } |
|
| 72 | + } |
|
| 73 | 73 | } |