@@ -29,100 +29,100 @@ |
||
| 29 | 29 | use OCP\ISession; |
| 30 | 30 | |
| 31 | 31 | class DateTimeZone implements IDateTimeZone { |
| 32 | - /** @var IConfig */ |
|
| 33 | - protected $config; |
|
| 32 | + /** @var IConfig */ |
|
| 33 | + protected $config; |
|
| 34 | 34 | |
| 35 | - /** @var ISession */ |
|
| 36 | - protected $session; |
|
| 35 | + /** @var ISession */ |
|
| 36 | + protected $session; |
|
| 37 | 37 | |
| 38 | - /** |
|
| 39 | - * Constructor |
|
| 40 | - * |
|
| 41 | - * @param IConfig $config |
|
| 42 | - * @param ISession $session |
|
| 43 | - */ |
|
| 44 | - public function __construct(IConfig $config, ISession $session) { |
|
| 45 | - $this->config = $config; |
|
| 46 | - $this->session = $session; |
|
| 47 | - } |
|
| 38 | + /** |
|
| 39 | + * Constructor |
|
| 40 | + * |
|
| 41 | + * @param IConfig $config |
|
| 42 | + * @param ISession $session |
|
| 43 | + */ |
|
| 44 | + public function __construct(IConfig $config, ISession $session) { |
|
| 45 | + $this->config = $config; |
|
| 46 | + $this->session = $session; |
|
| 47 | + } |
|
| 48 | 48 | |
| 49 | - /** |
|
| 50 | - * Get the timezone of the current user, based on his session information and config data |
|
| 51 | - * |
|
| 52 | - * @param bool|int $timestamp |
|
| 53 | - * @return \DateTimeZone |
|
| 54 | - */ |
|
| 55 | - public function getTimeZone($timestamp = false) { |
|
| 56 | - $timeZone = $this->config->getUserValue($this->session->get('user_id'), 'core', 'timezone', null); |
|
| 57 | - if ($timeZone === null) { |
|
| 58 | - if ($this->session->exists('timezone')) { |
|
| 59 | - return $this->guessTimeZoneFromOffset($this->session->get('timezone'), $timestamp); |
|
| 60 | - } |
|
| 61 | - $timeZone = $this->getDefaultTimeZone(); |
|
| 62 | - } |
|
| 49 | + /** |
|
| 50 | + * Get the timezone of the current user, based on his session information and config data |
|
| 51 | + * |
|
| 52 | + * @param bool|int $timestamp |
|
| 53 | + * @return \DateTimeZone |
|
| 54 | + */ |
|
| 55 | + public function getTimeZone($timestamp = false) { |
|
| 56 | + $timeZone = $this->config->getUserValue($this->session->get('user_id'), 'core', 'timezone', null); |
|
| 57 | + if ($timeZone === null) { |
|
| 58 | + if ($this->session->exists('timezone')) { |
|
| 59 | + return $this->guessTimeZoneFromOffset($this->session->get('timezone'), $timestamp); |
|
| 60 | + } |
|
| 61 | + $timeZone = $this->getDefaultTimeZone(); |
|
| 62 | + } |
|
| 63 | 63 | |
| 64 | - try { |
|
| 65 | - return new \DateTimeZone($timeZone); |
|
| 66 | - } catch (\Exception $e) { |
|
| 67 | - \OCP\Util::writeLog('datetimezone', 'Failed to created DateTimeZone "' . $timeZone . "'", \OCP\Util::DEBUG); |
|
| 68 | - return new \DateTimeZone($this->getDefaultTimeZone()); |
|
| 69 | - } |
|
| 70 | - } |
|
| 64 | + try { |
|
| 65 | + return new \DateTimeZone($timeZone); |
|
| 66 | + } catch (\Exception $e) { |
|
| 67 | + \OCP\Util::writeLog('datetimezone', 'Failed to created DateTimeZone "' . $timeZone . "'", \OCP\Util::DEBUG); |
|
| 68 | + return new \DateTimeZone($this->getDefaultTimeZone()); |
|
| 69 | + } |
|
| 70 | + } |
|
| 71 | 71 | |
| 72 | - /** |
|
| 73 | - * Guess the DateTimeZone for a given offset |
|
| 74 | - * |
|
| 75 | - * We first try to find a Etc/GMT* timezone, if that does not exist, |
|
| 76 | - * we try to find it manually, before falling back to UTC. |
|
| 77 | - * |
|
| 78 | - * @param mixed $offset |
|
| 79 | - * @param bool|int $timestamp |
|
| 80 | - * @return \DateTimeZone |
|
| 81 | - */ |
|
| 82 | - protected function guessTimeZoneFromOffset($offset, $timestamp) { |
|
| 83 | - try { |
|
| 84 | - // Note: the timeZone name is the inverse to the offset, |
|
| 85 | - // so a positive offset means negative timeZone |
|
| 86 | - // and the other way around. |
|
| 87 | - if ($offset > 0) { |
|
| 88 | - $timeZone = 'Etc/GMT-' . $offset; |
|
| 89 | - } else { |
|
| 90 | - $timeZone = 'Etc/GMT+' . abs($offset); |
|
| 91 | - } |
|
| 72 | + /** |
|
| 73 | + * Guess the DateTimeZone for a given offset |
|
| 74 | + * |
|
| 75 | + * We first try to find a Etc/GMT* timezone, if that does not exist, |
|
| 76 | + * we try to find it manually, before falling back to UTC. |
|
| 77 | + * |
|
| 78 | + * @param mixed $offset |
|
| 79 | + * @param bool|int $timestamp |
|
| 80 | + * @return \DateTimeZone |
|
| 81 | + */ |
|
| 82 | + protected function guessTimeZoneFromOffset($offset, $timestamp) { |
|
| 83 | + try { |
|
| 84 | + // Note: the timeZone name is the inverse to the offset, |
|
| 85 | + // so a positive offset means negative timeZone |
|
| 86 | + // and the other way around. |
|
| 87 | + if ($offset > 0) { |
|
| 88 | + $timeZone = 'Etc/GMT-' . $offset; |
|
| 89 | + } else { |
|
| 90 | + $timeZone = 'Etc/GMT+' . abs($offset); |
|
| 91 | + } |
|
| 92 | 92 | |
| 93 | - return new \DateTimeZone($timeZone); |
|
| 94 | - } catch (\Exception $e) { |
|
| 95 | - // If the offset has no Etc/GMT* timezone, |
|
| 96 | - // we try to guess one timezone that has the same offset |
|
| 97 | - foreach (\DateTimeZone::listIdentifiers() as $timeZone) { |
|
| 98 | - $dtz = new \DateTimeZone($timeZone); |
|
| 99 | - $dateTime = new \DateTime(); |
|
| 93 | + return new \DateTimeZone($timeZone); |
|
| 94 | + } catch (\Exception $e) { |
|
| 95 | + // If the offset has no Etc/GMT* timezone, |
|
| 96 | + // we try to guess one timezone that has the same offset |
|
| 97 | + foreach (\DateTimeZone::listIdentifiers() as $timeZone) { |
|
| 98 | + $dtz = new \DateTimeZone($timeZone); |
|
| 99 | + $dateTime = new \DateTime(); |
|
| 100 | 100 | |
| 101 | - if ($timestamp !== false) { |
|
| 102 | - $dateTime->setTimestamp($timestamp); |
|
| 103 | - } |
|
| 101 | + if ($timestamp !== false) { |
|
| 102 | + $dateTime->setTimestamp($timestamp); |
|
| 103 | + } |
|
| 104 | 104 | |
| 105 | - $dtOffset = $dtz->getOffset($dateTime); |
|
| 106 | - if ($dtOffset == 3600 * $offset) { |
|
| 107 | - return $dtz; |
|
| 108 | - } |
|
| 109 | - } |
|
| 105 | + $dtOffset = $dtz->getOffset($dateTime); |
|
| 106 | + if ($dtOffset == 3600 * $offset) { |
|
| 107 | + return $dtz; |
|
| 108 | + } |
|
| 109 | + } |
|
| 110 | 110 | |
| 111 | - // No timezone found, fallback to UTC |
|
| 112 | - \OCP\Util::writeLog('datetimezone', 'Failed to find DateTimeZone for offset "' . $offset . "'", \OCP\Util::DEBUG); |
|
| 113 | - return new \DateTimeZone($this->getDefaultTimeZone()); |
|
| 114 | - } |
|
| 115 | - } |
|
| 111 | + // No timezone found, fallback to UTC |
|
| 112 | + \OCP\Util::writeLog('datetimezone', 'Failed to find DateTimeZone for offset "' . $offset . "'", \OCP\Util::DEBUG); |
|
| 113 | + return new \DateTimeZone($this->getDefaultTimeZone()); |
|
| 114 | + } |
|
| 115 | + } |
|
| 116 | 116 | |
| 117 | - /** |
|
| 118 | - * Get the default timezone of the server |
|
| 119 | - * |
|
| 120 | - * Falls back to UTC if it is not yet set. |
|
| 121 | - * |
|
| 122 | - * @return string |
|
| 123 | - */ |
|
| 124 | - protected function getDefaultTimeZone() { |
|
| 125 | - $serverTimeZone = date_default_timezone_get(); |
|
| 126 | - return $serverTimeZone ?: 'UTC'; |
|
| 127 | - } |
|
| 117 | + /** |
|
| 118 | + * Get the default timezone of the server |
|
| 119 | + * |
|
| 120 | + * Falls back to UTC if it is not yet set. |
|
| 121 | + * |
|
| 122 | + * @return string |
|
| 123 | + */ |
|
| 124 | + protected function getDefaultTimeZone() { |
|
| 125 | + $serverTimeZone = date_default_timezone_get(); |
|
| 126 | + return $serverTimeZone ?: 'UTC'; |
|
| 127 | + } |
|
| 128 | 128 | } |
@@ -64,7 +64,7 @@ discard block |
||
| 64 | 64 | try { |
| 65 | 65 | return new \DateTimeZone($timeZone); |
| 66 | 66 | } catch (\Exception $e) { |
| 67 | - \OCP\Util::writeLog('datetimezone', 'Failed to created DateTimeZone "' . $timeZone . "'", \OCP\Util::DEBUG); |
|
| 67 | + \OCP\Util::writeLog('datetimezone', 'Failed to created DateTimeZone "'.$timeZone."'", \OCP\Util::DEBUG); |
|
| 68 | 68 | return new \DateTimeZone($this->getDefaultTimeZone()); |
| 69 | 69 | } |
| 70 | 70 | } |
@@ -85,9 +85,9 @@ discard block |
||
| 85 | 85 | // so a positive offset means negative timeZone |
| 86 | 86 | // and the other way around. |
| 87 | 87 | if ($offset > 0) { |
| 88 | - $timeZone = 'Etc/GMT-' . $offset; |
|
| 88 | + $timeZone = 'Etc/GMT-'.$offset; |
|
| 89 | 89 | } else { |
| 90 | - $timeZone = 'Etc/GMT+' . abs($offset); |
|
| 90 | + $timeZone = 'Etc/GMT+'.abs($offset); |
|
| 91 | 91 | } |
| 92 | 92 | |
| 93 | 93 | return new \DateTimeZone($timeZone); |
@@ -109,7 +109,7 @@ discard block |
||
| 109 | 109 | } |
| 110 | 110 | |
| 111 | 111 | // No timezone found, fallback to UTC |
| 112 | - \OCP\Util::writeLog('datetimezone', 'Failed to find DateTimeZone for offset "' . $offset . "'", \OCP\Util::DEBUG); |
|
| 112 | + \OCP\Util::writeLog('datetimezone', 'Failed to find DateTimeZone for offset "'.$offset."'", \OCP\Util::DEBUG); |
|
| 113 | 113 | return new \DateTimeZone($this->getDefaultTimeZone()); |
| 114 | 114 | } |
| 115 | 115 | } |
@@ -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', 'OC\Tagging\Tag'); |
|
| 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', 'OC\Tagging\Tag'); |
|
| 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 | |
@@ -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())); |
@@ -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') { |
@@ -28,38 +28,38 @@ |
||
| 28 | 28 | use OCP\ILogger; |
| 29 | 29 | |
| 30 | 30 | class CachingRouter extends Router { |
| 31 | - /** |
|
| 32 | - * @var \OCP\ICache |
|
| 33 | - */ |
|
| 34 | - protected $cache; |
|
| 31 | + /** |
|
| 32 | + * @var \OCP\ICache |
|
| 33 | + */ |
|
| 34 | + protected $cache; |
|
| 35 | 35 | |
| 36 | - /** |
|
| 37 | - * @param \OCP\ICache $cache |
|
| 38 | - * @param ILogger $logger |
|
| 39 | - */ |
|
| 40 | - public function __construct($cache, ILogger $logger) { |
|
| 41 | - $this->cache = $cache; |
|
| 42 | - parent::__construct($logger); |
|
| 43 | - } |
|
| 36 | + /** |
|
| 37 | + * @param \OCP\ICache $cache |
|
| 38 | + * @param ILogger $logger |
|
| 39 | + */ |
|
| 40 | + public function __construct($cache, ILogger $logger) { |
|
| 41 | + $this->cache = $cache; |
|
| 42 | + parent::__construct($logger); |
|
| 43 | + } |
|
| 44 | 44 | |
| 45 | - /** |
|
| 46 | - * Generate url based on $name and $parameters |
|
| 47 | - * |
|
| 48 | - * @param string $name Name of the route to use. |
|
| 49 | - * @param array $parameters Parameters for the route |
|
| 50 | - * @param bool $absolute |
|
| 51 | - * @return string |
|
| 52 | - */ |
|
| 53 | - public function generate($name, $parameters = array(), $absolute = false) { |
|
| 54 | - asort($parameters); |
|
| 55 | - $key = $this->context->getHost() . '#' . $this->context->getBaseUrl() . $name . sha1(json_encode($parameters)) . intval($absolute); |
|
| 56 | - $cachedKey = $this->cache->get($key); |
|
| 57 | - if ($cachedKey) { |
|
| 58 | - return $cachedKey; |
|
| 59 | - } else { |
|
| 60 | - $url = parent::generate($name, $parameters, $absolute); |
|
| 61 | - $this->cache->set($key, $url, 3600); |
|
| 62 | - return $url; |
|
| 63 | - } |
|
| 64 | - } |
|
| 45 | + /** |
|
| 46 | + * Generate url based on $name and $parameters |
|
| 47 | + * |
|
| 48 | + * @param string $name Name of the route to use. |
|
| 49 | + * @param array $parameters Parameters for the route |
|
| 50 | + * @param bool $absolute |
|
| 51 | + * @return string |
|
| 52 | + */ |
|
| 53 | + public function generate($name, $parameters = array(), $absolute = false) { |
|
| 54 | + asort($parameters); |
|
| 55 | + $key = $this->context->getHost() . '#' . $this->context->getBaseUrl() . $name . sha1(json_encode($parameters)) . intval($absolute); |
|
| 56 | + $cachedKey = $this->cache->get($key); |
|
| 57 | + if ($cachedKey) { |
|
| 58 | + return $cachedKey; |
|
| 59 | + } else { |
|
| 60 | + $url = parent::generate($name, $parameters, $absolute); |
|
| 61 | + $this->cache->set($key, $url, 3600); |
|
| 62 | + return $url; |
|
| 63 | + } |
|
| 64 | + } |
|
| 65 | 65 | } |
@@ -52,7 +52,7 @@ |
||
| 52 | 52 | */ |
| 53 | 53 | public function generate($name, $parameters = array(), $absolute = false) { |
| 54 | 54 | asort($parameters); |
| 55 | - $key = $this->context->getHost() . '#' . $this->context->getBaseUrl() . $name . sha1(json_encode($parameters)) . intval($absolute); |
|
| 55 | + $key = $this->context->getHost().'#'.$this->context->getBaseUrl().$name.sha1(json_encode($parameters)).intval($absolute); |
|
| 56 | 56 | $cachedKey = $this->cache->get($key); |
| 57 | 57 | if ($cachedKey) { |
| 58 | 58 | return $cachedKey; |
@@ -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 | } |
@@ -27,164 +27,164 @@ |
||
| 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 array |
|
| 123 | - */ |
|
| 124 | - public function getAddressBooks() { |
|
| 125 | - $this->loadAddressBooks(); |
|
| 126 | - $result = array(); |
|
| 127 | - foreach($this->addressBooks as $addressBook) { |
|
| 128 | - $result[$addressBook->getKey()] = $addressBook->getDisplayName(); |
|
| 129 | - } |
|
| 130 | - |
|
| 131 | - return $result; |
|
| 132 | - } |
|
| 133 | - |
|
| 134 | - /** |
|
| 135 | - * removes all registered address book instances |
|
| 136 | - */ |
|
| 137 | - public function clear() { |
|
| 138 | - $this->addressBooks = array(); |
|
| 139 | - $this->addressBookLoaders = array(); |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - /** |
|
| 143 | - * @var \OCP\IAddressBook[] which holds all registered address books |
|
| 144 | - */ |
|
| 145 | - private $addressBooks = array(); |
|
| 146 | - |
|
| 147 | - /** |
|
| 148 | - * @var \Closure[] to call to load/register address books |
|
| 149 | - */ |
|
| 150 | - private $addressBookLoaders = array(); |
|
| 151 | - |
|
| 152 | - /** |
|
| 153 | - * In order to improve lazy loading a closure can be registered which will be called in case |
|
| 154 | - * address books are actually requested |
|
| 155 | - * |
|
| 156 | - * @param \Closure $callable |
|
| 157 | - */ |
|
| 158 | - public function register(\Closure $callable) |
|
| 159 | - { |
|
| 160 | - $this->addressBookLoaders[] = $callable; |
|
| 161 | - } |
|
| 162 | - |
|
| 163 | - /** |
|
| 164 | - * Get (and load when needed) the address book for $key |
|
| 165 | - * |
|
| 166 | - * @param string $addressBookKey |
|
| 167 | - * @return \OCP\IAddressBook |
|
| 168 | - */ |
|
| 169 | - protected function getAddressBook($addressBookKey) |
|
| 170 | - { |
|
| 171 | - $this->loadAddressBooks(); |
|
| 172 | - if (!array_key_exists($addressBookKey, $this->addressBooks)) { |
|
| 173 | - return null; |
|
| 174 | - } |
|
| 175 | - |
|
| 176 | - return $this->addressBooks[$addressBookKey]; |
|
| 177 | - } |
|
| 178 | - |
|
| 179 | - /** |
|
| 180 | - * Load all address books registered with 'register' |
|
| 181 | - */ |
|
| 182 | - protected function loadAddressBooks() |
|
| 183 | - { |
|
| 184 | - foreach($this->addressBookLoaders as $callable) { |
|
| 185 | - $callable($this); |
|
| 186 | - } |
|
| 187 | - $this->addressBookLoaders = array(); |
|
| 188 | - } |
|
| 189 | - } |
|
| 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 array |
|
| 123 | + */ |
|
| 124 | + public function getAddressBooks() { |
|
| 125 | + $this->loadAddressBooks(); |
|
| 126 | + $result = array(); |
|
| 127 | + foreach($this->addressBooks as $addressBook) { |
|
| 128 | + $result[$addressBook->getKey()] = $addressBook->getDisplayName(); |
|
| 129 | + } |
|
| 130 | + |
|
| 131 | + return $result; |
|
| 132 | + } |
|
| 133 | + |
|
| 134 | + /** |
|
| 135 | + * removes all registered address book instances |
|
| 136 | + */ |
|
| 137 | + public function clear() { |
|
| 138 | + $this->addressBooks = array(); |
|
| 139 | + $this->addressBookLoaders = array(); |
|
| 140 | + } |
|
| 141 | + |
|
| 142 | + /** |
|
| 143 | + * @var \OCP\IAddressBook[] which holds all registered address books |
|
| 144 | + */ |
|
| 145 | + private $addressBooks = array(); |
|
| 146 | + |
|
| 147 | + /** |
|
| 148 | + * @var \Closure[] to call to load/register address books |
|
| 149 | + */ |
|
| 150 | + private $addressBookLoaders = array(); |
|
| 151 | + |
|
| 152 | + /** |
|
| 153 | + * In order to improve lazy loading a closure can be registered which will be called in case |
|
| 154 | + * address books are actually requested |
|
| 155 | + * |
|
| 156 | + * @param \Closure $callable |
|
| 157 | + */ |
|
| 158 | + public function register(\Closure $callable) |
|
| 159 | + { |
|
| 160 | + $this->addressBookLoaders[] = $callable; |
|
| 161 | + } |
|
| 162 | + |
|
| 163 | + /** |
|
| 164 | + * Get (and load when needed) the address book for $key |
|
| 165 | + * |
|
| 166 | + * @param string $addressBookKey |
|
| 167 | + * @return \OCP\IAddressBook |
|
| 168 | + */ |
|
| 169 | + protected function getAddressBook($addressBookKey) |
|
| 170 | + { |
|
| 171 | + $this->loadAddressBooks(); |
|
| 172 | + if (!array_key_exists($addressBookKey, $this->addressBooks)) { |
|
| 173 | + return null; |
|
| 174 | + } |
|
| 175 | + |
|
| 176 | + return $this->addressBooks[$addressBookKey]; |
|
| 177 | + } |
|
| 178 | + |
|
| 179 | + /** |
|
| 180 | + * Load all address books registered with 'register' |
|
| 181 | + */ |
|
| 182 | + protected function loadAddressBooks() |
|
| 183 | + { |
|
| 184 | + foreach($this->addressBookLoaders as $callable) { |
|
| 185 | + $callable($this); |
|
| 186 | + } |
|
| 187 | + $this->addressBookLoaders = array(); |
|
| 188 | + } |
|
| 189 | + } |
|
| 190 | 190 | } |
@@ -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(); |
@@ -412,7 +412,7 @@ |
||
| 412 | 412 | $appDir = OC_App::getInstallPath() . '/' . $appId; |
| 413 | 413 | OC_Helper::rmdirr($appDir); |
| 414 | 414 | return true; |
| 415 | - }else{ |
|
| 415 | + } else{ |
|
| 416 | 416 | \OCP\Util::writeLog('core', 'can\'t remove app '.$appId.'. It is not installed.', \OCP\Util::ERROR); |
| 417 | 417 | |
| 418 | 418 | return false; |
@@ -36,17 +36,12 @@ |
||
| 36 | 36 | namespace OC; |
| 37 | 37 | |
| 38 | 38 | use Doctrine\DBAL\Exception\TableExistsException; |
| 39 | -use OC\App\AppManager; |
|
| 40 | 39 | use OC\App\AppStore\Bundles\Bundle; |
| 41 | 40 | use OC\App\AppStore\Fetcher\AppFetcher; |
| 42 | -use OC\App\CodeChecker\CodeChecker; |
|
| 43 | -use OC\App\CodeChecker\EmptyCheck; |
|
| 44 | -use OC\App\CodeChecker\PrivateCheck; |
|
| 45 | 41 | use OC\Archive\TAR; |
| 46 | 42 | use OC_App; |
| 47 | 43 | use OC_DB; |
| 48 | 44 | use OC_Helper; |
| 49 | -use OCP\App\IAppManager; |
|
| 50 | 45 | use OCP\Http\Client\IClientService; |
| 51 | 46 | use OCP\IConfig; |
| 52 | 47 | use OCP\ILogger; |
@@ -57,546 +57,546 @@ |
||
| 57 | 57 | * This class provides the functionality needed to install, update and remove apps |
| 58 | 58 | */ |
| 59 | 59 | class Installer { |
| 60 | - /** @var AppFetcher */ |
|
| 61 | - private $appFetcher; |
|
| 62 | - /** @var IClientService */ |
|
| 63 | - private $clientService; |
|
| 64 | - /** @var ITempManager */ |
|
| 65 | - private $tempManager; |
|
| 66 | - /** @var ILogger */ |
|
| 67 | - private $logger; |
|
| 68 | - /** @var IConfig */ |
|
| 69 | - private $config; |
|
| 70 | - /** @var array - for caching the result of app fetcher */ |
|
| 71 | - private $apps = null; |
|
| 72 | - /** @var bool|null - for caching the result of the ready status */ |
|
| 73 | - private $isInstanceReadyForUpdates = null; |
|
| 74 | - |
|
| 75 | - /** |
|
| 76 | - * @param AppFetcher $appFetcher |
|
| 77 | - * @param IClientService $clientService |
|
| 78 | - * @param ITempManager $tempManager |
|
| 79 | - * @param ILogger $logger |
|
| 80 | - * @param IConfig $config |
|
| 81 | - */ |
|
| 82 | - public function __construct(AppFetcher $appFetcher, |
|
| 83 | - IClientService $clientService, |
|
| 84 | - ITempManager $tempManager, |
|
| 85 | - ILogger $logger, |
|
| 86 | - IConfig $config) { |
|
| 87 | - $this->appFetcher = $appFetcher; |
|
| 88 | - $this->clientService = $clientService; |
|
| 89 | - $this->tempManager = $tempManager; |
|
| 90 | - $this->logger = $logger; |
|
| 91 | - $this->config = $config; |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - /** |
|
| 95 | - * Installs an app that is located in one of the app folders already |
|
| 96 | - * |
|
| 97 | - * @param string $appId App to install |
|
| 98 | - * @throws \Exception |
|
| 99 | - * @return string app ID |
|
| 100 | - */ |
|
| 101 | - public function installApp($appId) { |
|
| 102 | - $app = \OC_App::findAppInDirectories($appId); |
|
| 103 | - if($app === false) { |
|
| 104 | - throw new \Exception('App not found in any app directory'); |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - $basedir = $app['path'].'/'.$appId; |
|
| 108 | - $info = OC_App::getAppInfo($basedir.'/appinfo/info.xml', true); |
|
| 109 | - |
|
| 110 | - $l = \OC::$server->getL10N('core'); |
|
| 111 | - |
|
| 112 | - if(!is_array($info)) { |
|
| 113 | - throw new \Exception( |
|
| 114 | - $l->t('App "%s" cannot be installed because appinfo file cannot be read.', |
|
| 115 | - [$info['name']] |
|
| 116 | - ) |
|
| 117 | - ); |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - $version = \OCP\Util::getVersion(); |
|
| 121 | - if (!\OC_App::isAppCompatible($version, $info)) { |
|
| 122 | - throw new \Exception( |
|
| 123 | - // TODO $l |
|
| 124 | - $l->t('App "%s" cannot be installed because it is not compatible with this version of the server.', |
|
| 125 | - [$info['name']] |
|
| 126 | - ) |
|
| 127 | - ); |
|
| 128 | - } |
|
| 129 | - |
|
| 130 | - // check for required dependencies |
|
| 131 | - \OC_App::checkAppDependencies($this->config, $l, $info); |
|
| 132 | - \OC_App::registerAutoloading($appId, $basedir); |
|
| 133 | - |
|
| 134 | - //install the database |
|
| 135 | - if(is_file($basedir.'/appinfo/database.xml')) { |
|
| 136 | - if (\OC::$server->getAppConfig()->getValue($info['id'], 'installed_version') === null) { |
|
| 137 | - OC_DB::createDbFromStructure($basedir.'/appinfo/database.xml'); |
|
| 138 | - } else { |
|
| 139 | - OC_DB::updateDbFromStructure($basedir.'/appinfo/database.xml'); |
|
| 140 | - } |
|
| 141 | - } else { |
|
| 142 | - $ms = new \OC\DB\MigrationService($info['id'], \OC::$server->getDatabaseConnection()); |
|
| 143 | - $ms->migrate(); |
|
| 144 | - } |
|
| 145 | - |
|
| 146 | - \OC_App::setupBackgroundJobs($info['background-jobs']); |
|
| 147 | - if(isset($info['settings']) && is_array($info['settings'])) { |
|
| 148 | - \OC::$server->getSettingsManager()->setupSettings($info['settings']); |
|
| 149 | - } |
|
| 150 | - |
|
| 151 | - //run appinfo/install.php |
|
| 152 | - if((!isset($data['noinstall']) or $data['noinstall']==false)) { |
|
| 153 | - self::includeAppScript($basedir . '/appinfo/install.php'); |
|
| 154 | - } |
|
| 155 | - |
|
| 156 | - $appData = OC_App::getAppInfo($appId); |
|
| 157 | - OC_App::executeRepairSteps($appId, $appData['repair-steps']['install']); |
|
| 158 | - |
|
| 159 | - //set the installed version |
|
| 160 | - \OC::$server->getConfig()->setAppValue($info['id'], 'installed_version', OC_App::getAppVersion($info['id'], false)); |
|
| 161 | - \OC::$server->getConfig()->setAppValue($info['id'], 'enabled', 'no'); |
|
| 162 | - |
|
| 163 | - //set remote/public handlers |
|
| 164 | - foreach($info['remote'] as $name=>$path) { |
|
| 165 | - \OC::$server->getConfig()->setAppValue('core', 'remote_'.$name, $info['id'].'/'.$path); |
|
| 166 | - } |
|
| 167 | - foreach($info['public'] as $name=>$path) { |
|
| 168 | - \OC::$server->getConfig()->setAppValue('core', 'public_'.$name, $info['id'].'/'.$path); |
|
| 169 | - } |
|
| 170 | - |
|
| 171 | - OC_App::setAppTypes($info['id']); |
|
| 172 | - |
|
| 173 | - return $info['id']; |
|
| 174 | - } |
|
| 175 | - |
|
| 176 | - /** |
|
| 177 | - * @brief checks whether or not an app is installed |
|
| 178 | - * @param string $app app |
|
| 179 | - * @returns bool |
|
| 180 | - * |
|
| 181 | - * Checks whether or not an app is installed, i.e. registered in apps table. |
|
| 182 | - */ |
|
| 183 | - public static function isInstalled( $app ) { |
|
| 184 | - return (\OC::$server->getConfig()->getAppValue($app, "installed_version", null) !== null); |
|
| 185 | - } |
|
| 186 | - |
|
| 187 | - /** |
|
| 188 | - * Updates the specified app from the appstore |
|
| 189 | - * |
|
| 190 | - * @param string $appId |
|
| 191 | - * @return bool |
|
| 192 | - */ |
|
| 193 | - public function updateAppstoreApp($appId) { |
|
| 194 | - if($this->isUpdateAvailable($appId)) { |
|
| 195 | - try { |
|
| 196 | - $this->downloadApp($appId); |
|
| 197 | - } catch (\Exception $e) { |
|
| 198 | - $this->logger->error($e->getMessage(), ['app' => 'core']); |
|
| 199 | - return false; |
|
| 200 | - } |
|
| 201 | - return OC_App::updateApp($appId); |
|
| 202 | - } |
|
| 203 | - |
|
| 204 | - return false; |
|
| 205 | - } |
|
| 206 | - |
|
| 207 | - /** |
|
| 208 | - * Downloads an app and puts it into the app directory |
|
| 209 | - * |
|
| 210 | - * @param string $appId |
|
| 211 | - * |
|
| 212 | - * @throws \Exception If the installation was not successful |
|
| 213 | - */ |
|
| 214 | - public function downloadApp($appId) { |
|
| 215 | - $appId = strtolower($appId); |
|
| 216 | - |
|
| 217 | - $apps = $this->appFetcher->get(); |
|
| 218 | - foreach($apps as $app) { |
|
| 219 | - if($app['id'] === $appId) { |
|
| 220 | - // Load the certificate |
|
| 221 | - $certificate = new X509(); |
|
| 222 | - $certificate->loadCA(file_get_contents(__DIR__ . '/../../resources/codesigning/root.crt')); |
|
| 223 | - $loadedCertificate = $certificate->loadX509($app['certificate']); |
|
| 224 | - |
|
| 225 | - // Verify if the certificate has been revoked |
|
| 226 | - $crl = new X509(); |
|
| 227 | - $crl->loadCA(file_get_contents(__DIR__ . '/../../resources/codesigning/root.crt')); |
|
| 228 | - $crl->loadCRL(file_get_contents(__DIR__ . '/../../resources/codesigning/root.crl')); |
|
| 229 | - if($crl->validateSignature() !== true) { |
|
| 230 | - throw new \Exception('Could not validate CRL signature'); |
|
| 231 | - } |
|
| 232 | - $csn = $loadedCertificate['tbsCertificate']['serialNumber']->toString(); |
|
| 233 | - $revoked = $crl->getRevoked($csn); |
|
| 234 | - if ($revoked !== false) { |
|
| 235 | - throw new \Exception( |
|
| 236 | - sprintf( |
|
| 237 | - 'Certificate "%s" has been revoked', |
|
| 238 | - $csn |
|
| 239 | - ) |
|
| 240 | - ); |
|
| 241 | - } |
|
| 242 | - |
|
| 243 | - // Verify if the certificate has been issued by the Nextcloud Code Authority CA |
|
| 244 | - if($certificate->validateSignature() !== true) { |
|
| 245 | - throw new \Exception( |
|
| 246 | - sprintf( |
|
| 247 | - 'App with id %s has a certificate not issued by a trusted Code Signing Authority', |
|
| 248 | - $appId |
|
| 249 | - ) |
|
| 250 | - ); |
|
| 251 | - } |
|
| 252 | - |
|
| 253 | - // Verify if the certificate is issued for the requested app id |
|
| 254 | - $certInfo = openssl_x509_parse($app['certificate']); |
|
| 255 | - if(!isset($certInfo['subject']['CN'])) { |
|
| 256 | - throw new \Exception( |
|
| 257 | - sprintf( |
|
| 258 | - 'App with id %s has a cert with no CN', |
|
| 259 | - $appId |
|
| 260 | - ) |
|
| 261 | - ); |
|
| 262 | - } |
|
| 263 | - if($certInfo['subject']['CN'] !== $appId) { |
|
| 264 | - throw new \Exception( |
|
| 265 | - sprintf( |
|
| 266 | - 'App with id %s has a cert issued to %s', |
|
| 267 | - $appId, |
|
| 268 | - $certInfo['subject']['CN'] |
|
| 269 | - ) |
|
| 270 | - ); |
|
| 271 | - } |
|
| 272 | - |
|
| 273 | - // Download the release |
|
| 274 | - $tempFile = $this->tempManager->getTemporaryFile('.tar.gz'); |
|
| 275 | - $client = $this->clientService->newClient(); |
|
| 276 | - $client->get($app['releases'][0]['download'], ['save_to' => $tempFile]); |
|
| 277 | - |
|
| 278 | - // Check if the signature actually matches the downloaded content |
|
| 279 | - $certificate = openssl_get_publickey($app['certificate']); |
|
| 280 | - $verified = (bool)openssl_verify(file_get_contents($tempFile), base64_decode($app['releases'][0]['signature']), $certificate, OPENSSL_ALGO_SHA512); |
|
| 281 | - openssl_free_key($certificate); |
|
| 282 | - |
|
| 283 | - if($verified === true) { |
|
| 284 | - // Seems to match, let's proceed |
|
| 285 | - $extractDir = $this->tempManager->getTemporaryFolder(); |
|
| 286 | - $archive = new TAR($tempFile); |
|
| 287 | - |
|
| 288 | - if($archive) { |
|
| 289 | - if (!$archive->extract($extractDir)) { |
|
| 290 | - throw new \Exception( |
|
| 291 | - sprintf( |
|
| 292 | - 'Could not extract app %s', |
|
| 293 | - $appId |
|
| 294 | - ) |
|
| 295 | - ); |
|
| 296 | - } |
|
| 297 | - $allFiles = scandir($extractDir); |
|
| 298 | - $folders = array_diff($allFiles, ['.', '..']); |
|
| 299 | - $folders = array_values($folders); |
|
| 300 | - |
|
| 301 | - if(count($folders) > 1) { |
|
| 302 | - throw new \Exception( |
|
| 303 | - sprintf( |
|
| 304 | - 'Extracted app %s has more than 1 folder', |
|
| 305 | - $appId |
|
| 306 | - ) |
|
| 307 | - ); |
|
| 308 | - } |
|
| 309 | - |
|
| 310 | - // Check if appinfo/info.xml has the same app ID as well |
|
| 311 | - $loadEntities = libxml_disable_entity_loader(false); |
|
| 312 | - $xml = simplexml_load_file($extractDir . '/' . $folders[0] . '/appinfo/info.xml'); |
|
| 313 | - libxml_disable_entity_loader($loadEntities); |
|
| 314 | - if((string)$xml->id !== $appId) { |
|
| 315 | - throw new \Exception( |
|
| 316 | - sprintf( |
|
| 317 | - 'App for id %s has a wrong app ID in info.xml: %s', |
|
| 318 | - $appId, |
|
| 319 | - (string)$xml->id |
|
| 320 | - ) |
|
| 321 | - ); |
|
| 322 | - } |
|
| 323 | - |
|
| 324 | - // Check if the version is lower than before |
|
| 325 | - $currentVersion = OC_App::getAppVersion($appId); |
|
| 326 | - $newVersion = (string)$xml->version; |
|
| 327 | - if(version_compare($currentVersion, $newVersion) === 1) { |
|
| 328 | - throw new \Exception( |
|
| 329 | - sprintf( |
|
| 330 | - 'App for id %s has version %s and tried to update to lower version %s', |
|
| 331 | - $appId, |
|
| 332 | - $currentVersion, |
|
| 333 | - $newVersion |
|
| 334 | - ) |
|
| 335 | - ); |
|
| 336 | - } |
|
| 337 | - |
|
| 338 | - $baseDir = OC_App::getInstallPath() . '/' . $appId; |
|
| 339 | - // Remove old app with the ID if existent |
|
| 340 | - OC_Helper::rmdirr($baseDir); |
|
| 341 | - // Move to app folder |
|
| 342 | - if(@mkdir($baseDir)) { |
|
| 343 | - $extractDir .= '/' . $folders[0]; |
|
| 344 | - OC_Helper::copyr($extractDir, $baseDir); |
|
| 345 | - } |
|
| 346 | - OC_Helper::copyr($extractDir, $baseDir); |
|
| 347 | - OC_Helper::rmdirr($extractDir); |
|
| 348 | - return; |
|
| 349 | - } else { |
|
| 350 | - throw new \Exception( |
|
| 351 | - sprintf( |
|
| 352 | - 'Could not extract app with ID %s to %s', |
|
| 353 | - $appId, |
|
| 354 | - $extractDir |
|
| 355 | - ) |
|
| 356 | - ); |
|
| 357 | - } |
|
| 358 | - } else { |
|
| 359 | - // Signature does not match |
|
| 360 | - throw new \Exception( |
|
| 361 | - sprintf( |
|
| 362 | - 'App with id %s has invalid signature', |
|
| 363 | - $appId |
|
| 364 | - ) |
|
| 365 | - ); |
|
| 366 | - } |
|
| 367 | - } |
|
| 368 | - } |
|
| 369 | - |
|
| 370 | - throw new \Exception( |
|
| 371 | - sprintf( |
|
| 372 | - 'Could not download app %s', |
|
| 373 | - $appId |
|
| 374 | - ) |
|
| 375 | - ); |
|
| 376 | - } |
|
| 377 | - |
|
| 378 | - /** |
|
| 379 | - * Check if an update for the app is available |
|
| 380 | - * |
|
| 381 | - * @param string $appId |
|
| 382 | - * @return string|false false or the version number of the update |
|
| 383 | - */ |
|
| 384 | - public function isUpdateAvailable($appId) { |
|
| 385 | - if ($this->isInstanceReadyForUpdates === null) { |
|
| 386 | - $installPath = OC_App::getInstallPath(); |
|
| 387 | - if ($installPath === false || $installPath === null) { |
|
| 388 | - $this->isInstanceReadyForUpdates = false; |
|
| 389 | - } else { |
|
| 390 | - $this->isInstanceReadyForUpdates = true; |
|
| 391 | - } |
|
| 392 | - } |
|
| 393 | - |
|
| 394 | - if ($this->isInstanceReadyForUpdates === false) { |
|
| 395 | - return false; |
|
| 396 | - } |
|
| 397 | - |
|
| 398 | - if ($this->apps === null) { |
|
| 399 | - $apps = $this->appFetcher->get(); |
|
| 400 | - } |
|
| 401 | - |
|
| 402 | - foreach($apps as $app) { |
|
| 403 | - if($app['id'] === $appId) { |
|
| 404 | - $currentVersion = OC_App::getAppVersion($appId); |
|
| 405 | - $newestVersion = $app['releases'][0]['version']; |
|
| 406 | - if (version_compare($newestVersion, $currentVersion, '>')) { |
|
| 407 | - return $newestVersion; |
|
| 408 | - } else { |
|
| 409 | - return false; |
|
| 410 | - } |
|
| 411 | - } |
|
| 412 | - } |
|
| 413 | - |
|
| 414 | - return false; |
|
| 415 | - } |
|
| 416 | - |
|
| 417 | - /** |
|
| 418 | - * Check if app is already downloaded |
|
| 419 | - * @param string $name name of the application to remove |
|
| 420 | - * @return boolean |
|
| 421 | - * |
|
| 422 | - * The function will check if the app is already downloaded in the apps repository |
|
| 423 | - */ |
|
| 424 | - public function isDownloaded($name) { |
|
| 425 | - foreach(\OC::$APPSROOTS as $dir) { |
|
| 426 | - $dirToTest = $dir['path']; |
|
| 427 | - $dirToTest .= '/'; |
|
| 428 | - $dirToTest .= $name; |
|
| 429 | - $dirToTest .= '/'; |
|
| 430 | - |
|
| 431 | - if (is_dir($dirToTest)) { |
|
| 432 | - return true; |
|
| 433 | - } |
|
| 434 | - } |
|
| 435 | - |
|
| 436 | - return false; |
|
| 437 | - } |
|
| 438 | - |
|
| 439 | - /** |
|
| 440 | - * Removes an app |
|
| 441 | - * @param string $appId ID of the application to remove |
|
| 442 | - * @return boolean |
|
| 443 | - * |
|
| 444 | - * |
|
| 445 | - * This function works as follows |
|
| 446 | - * -# call uninstall repair steps |
|
| 447 | - * -# removing the files |
|
| 448 | - * |
|
| 449 | - * The function will not delete preferences, tables and the configuration, |
|
| 450 | - * this has to be done by the function oc_app_uninstall(). |
|
| 451 | - */ |
|
| 452 | - public function removeApp($appId) { |
|
| 453 | - if($this->isDownloaded( $appId )) { |
|
| 454 | - $appDir = OC_App::getInstallPath() . '/' . $appId; |
|
| 455 | - OC_Helper::rmdirr($appDir); |
|
| 456 | - return true; |
|
| 457 | - }else{ |
|
| 458 | - \OCP\Util::writeLog('core', 'can\'t remove app '.$appId.'. It is not installed.', \OCP\Util::ERROR); |
|
| 459 | - |
|
| 460 | - return false; |
|
| 461 | - } |
|
| 462 | - |
|
| 463 | - } |
|
| 464 | - |
|
| 465 | - /** |
|
| 466 | - * Installs the app within the bundle and marks the bundle as installed |
|
| 467 | - * |
|
| 468 | - * @param Bundle $bundle |
|
| 469 | - * @throws \Exception If app could not get installed |
|
| 470 | - */ |
|
| 471 | - public function installAppBundle(Bundle $bundle) { |
|
| 472 | - $appIds = $bundle->getAppIdentifiers(); |
|
| 473 | - foreach($appIds as $appId) { |
|
| 474 | - if(!$this->isDownloaded($appId)) { |
|
| 475 | - $this->downloadApp($appId); |
|
| 476 | - } |
|
| 477 | - $this->installApp($appId); |
|
| 478 | - $app = new OC_App(); |
|
| 479 | - $app->enable($appId); |
|
| 480 | - } |
|
| 481 | - $bundles = json_decode($this->config->getAppValue('core', 'installed.bundles', json_encode([])), true); |
|
| 482 | - $bundles[] = $bundle->getIdentifier(); |
|
| 483 | - $this->config->setAppValue('core', 'installed.bundles', json_encode($bundles)); |
|
| 484 | - } |
|
| 485 | - |
|
| 486 | - /** |
|
| 487 | - * Installs shipped apps |
|
| 488 | - * |
|
| 489 | - * This function installs all apps found in the 'apps' directory that should be enabled by default; |
|
| 490 | - * @param bool $softErrors When updating we ignore errors and simply log them, better to have a |
|
| 491 | - * working ownCloud at the end instead of an aborted update. |
|
| 492 | - * @return array Array of error messages (appid => Exception) |
|
| 493 | - */ |
|
| 494 | - public static function installShippedApps($softErrors = false) { |
|
| 495 | - $errors = []; |
|
| 496 | - foreach(\OC::$APPSROOTS as $app_dir) { |
|
| 497 | - if($dir = opendir( $app_dir['path'] )) { |
|
| 498 | - while( false !== ( $filename = readdir( $dir ))) { |
|
| 499 | - if( substr( $filename, 0, 1 ) != '.' and is_dir($app_dir['path']."/$filename") ) { |
|
| 500 | - if( file_exists( $app_dir['path']."/$filename/appinfo/info.xml" )) { |
|
| 501 | - if(!Installer::isInstalled($filename)) { |
|
| 502 | - $info=OC_App::getAppInfo($filename); |
|
| 503 | - $enabled = isset($info['default_enable']); |
|
| 504 | - if (($enabled || in_array($filename, \OC::$server->getAppManager()->getAlwaysEnabledApps())) |
|
| 505 | - && \OC::$server->getConfig()->getAppValue($filename, 'enabled') !== 'no') { |
|
| 506 | - if ($softErrors) { |
|
| 507 | - try { |
|
| 508 | - Installer::installShippedApp($filename); |
|
| 509 | - } catch (HintException $e) { |
|
| 510 | - if ($e->getPrevious() instanceof TableExistsException) { |
|
| 511 | - $errors[$filename] = $e; |
|
| 512 | - continue; |
|
| 513 | - } |
|
| 514 | - throw $e; |
|
| 515 | - } |
|
| 516 | - } else { |
|
| 517 | - Installer::installShippedApp($filename); |
|
| 518 | - } |
|
| 519 | - \OC::$server->getConfig()->setAppValue($filename, 'enabled', 'yes'); |
|
| 520 | - } |
|
| 521 | - } |
|
| 522 | - } |
|
| 523 | - } |
|
| 524 | - } |
|
| 525 | - closedir( $dir ); |
|
| 526 | - } |
|
| 527 | - } |
|
| 528 | - |
|
| 529 | - return $errors; |
|
| 530 | - } |
|
| 531 | - |
|
| 532 | - /** |
|
| 533 | - * install an app already placed in the app folder |
|
| 534 | - * @param string $app id of the app to install |
|
| 535 | - * @return integer |
|
| 536 | - */ |
|
| 537 | - public static function installShippedApp($app) { |
|
| 538 | - //install the database |
|
| 539 | - $appPath = OC_App::getAppPath($app); |
|
| 540 | - \OC_App::registerAutoloading($app, $appPath); |
|
| 541 | - |
|
| 542 | - if(is_file("$appPath/appinfo/database.xml")) { |
|
| 543 | - try { |
|
| 544 | - OC_DB::createDbFromStructure("$appPath/appinfo/database.xml"); |
|
| 545 | - } catch (TableExistsException $e) { |
|
| 546 | - throw new HintException( |
|
| 547 | - 'Failed to enable app ' . $app, |
|
| 548 | - 'Please ask for help via one of our <a href="https://nextcloud.com/support/" target="_blank" rel="noreferrer noopener">support channels</a>.', |
|
| 549 | - 0, $e |
|
| 550 | - ); |
|
| 551 | - } |
|
| 552 | - } else { |
|
| 553 | - $ms = new \OC\DB\MigrationService($app, \OC::$server->getDatabaseConnection()); |
|
| 554 | - $ms->migrate(); |
|
| 555 | - } |
|
| 556 | - |
|
| 557 | - //run appinfo/install.php |
|
| 558 | - self::includeAppScript("$appPath/appinfo/install.php"); |
|
| 559 | - |
|
| 560 | - $info = OC_App::getAppInfo($app); |
|
| 561 | - if (is_null($info)) { |
|
| 562 | - return false; |
|
| 563 | - } |
|
| 564 | - \OC_App::setupBackgroundJobs($info['background-jobs']); |
|
| 565 | - |
|
| 566 | - OC_App::executeRepairSteps($app, $info['repair-steps']['install']); |
|
| 567 | - |
|
| 568 | - $config = \OC::$server->getConfig(); |
|
| 569 | - |
|
| 570 | - $config->setAppValue($app, 'installed_version', OC_App::getAppVersion($app)); |
|
| 571 | - if (array_key_exists('ocsid', $info)) { |
|
| 572 | - $config->setAppValue($app, 'ocsid', $info['ocsid']); |
|
| 573 | - } |
|
| 574 | - |
|
| 575 | - //set remote/public handlers |
|
| 576 | - foreach($info['remote'] as $name=>$path) { |
|
| 577 | - $config->setAppValue('core', 'remote_'.$name, $app.'/'.$path); |
|
| 578 | - } |
|
| 579 | - foreach($info['public'] as $name=>$path) { |
|
| 580 | - $config->setAppValue('core', 'public_'.$name, $app.'/'.$path); |
|
| 581 | - } |
|
| 582 | - |
|
| 583 | - OC_App::setAppTypes($info['id']); |
|
| 584 | - |
|
| 585 | - if(isset($info['settings']) && is_array($info['settings'])) { |
|
| 586 | - // requires that autoloading was registered for the app, |
|
| 587 | - // as happens before running the install.php some lines above |
|
| 588 | - \OC::$server->getSettingsManager()->setupSettings($info['settings']); |
|
| 589 | - } |
|
| 590 | - |
|
| 591 | - return $info['id']; |
|
| 592 | - } |
|
| 593 | - |
|
| 594 | - /** |
|
| 595 | - * @param string $script |
|
| 596 | - */ |
|
| 597 | - private static function includeAppScript($script) { |
|
| 598 | - if ( file_exists($script) ){ |
|
| 599 | - include $script; |
|
| 600 | - } |
|
| 601 | - } |
|
| 60 | + /** @var AppFetcher */ |
|
| 61 | + private $appFetcher; |
|
| 62 | + /** @var IClientService */ |
|
| 63 | + private $clientService; |
|
| 64 | + /** @var ITempManager */ |
|
| 65 | + private $tempManager; |
|
| 66 | + /** @var ILogger */ |
|
| 67 | + private $logger; |
|
| 68 | + /** @var IConfig */ |
|
| 69 | + private $config; |
|
| 70 | + /** @var array - for caching the result of app fetcher */ |
|
| 71 | + private $apps = null; |
|
| 72 | + /** @var bool|null - for caching the result of the ready status */ |
|
| 73 | + private $isInstanceReadyForUpdates = null; |
|
| 74 | + |
|
| 75 | + /** |
|
| 76 | + * @param AppFetcher $appFetcher |
|
| 77 | + * @param IClientService $clientService |
|
| 78 | + * @param ITempManager $tempManager |
|
| 79 | + * @param ILogger $logger |
|
| 80 | + * @param IConfig $config |
|
| 81 | + */ |
|
| 82 | + public function __construct(AppFetcher $appFetcher, |
|
| 83 | + IClientService $clientService, |
|
| 84 | + ITempManager $tempManager, |
|
| 85 | + ILogger $logger, |
|
| 86 | + IConfig $config) { |
|
| 87 | + $this->appFetcher = $appFetcher; |
|
| 88 | + $this->clientService = $clientService; |
|
| 89 | + $this->tempManager = $tempManager; |
|
| 90 | + $this->logger = $logger; |
|
| 91 | + $this->config = $config; |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + /** |
|
| 95 | + * Installs an app that is located in one of the app folders already |
|
| 96 | + * |
|
| 97 | + * @param string $appId App to install |
|
| 98 | + * @throws \Exception |
|
| 99 | + * @return string app ID |
|
| 100 | + */ |
|
| 101 | + public function installApp($appId) { |
|
| 102 | + $app = \OC_App::findAppInDirectories($appId); |
|
| 103 | + if($app === false) { |
|
| 104 | + throw new \Exception('App not found in any app directory'); |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + $basedir = $app['path'].'/'.$appId; |
|
| 108 | + $info = OC_App::getAppInfo($basedir.'/appinfo/info.xml', true); |
|
| 109 | + |
|
| 110 | + $l = \OC::$server->getL10N('core'); |
|
| 111 | + |
|
| 112 | + if(!is_array($info)) { |
|
| 113 | + throw new \Exception( |
|
| 114 | + $l->t('App "%s" cannot be installed because appinfo file cannot be read.', |
|
| 115 | + [$info['name']] |
|
| 116 | + ) |
|
| 117 | + ); |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + $version = \OCP\Util::getVersion(); |
|
| 121 | + if (!\OC_App::isAppCompatible($version, $info)) { |
|
| 122 | + throw new \Exception( |
|
| 123 | + // TODO $l |
|
| 124 | + $l->t('App "%s" cannot be installed because it is not compatible with this version of the server.', |
|
| 125 | + [$info['name']] |
|
| 126 | + ) |
|
| 127 | + ); |
|
| 128 | + } |
|
| 129 | + |
|
| 130 | + // check for required dependencies |
|
| 131 | + \OC_App::checkAppDependencies($this->config, $l, $info); |
|
| 132 | + \OC_App::registerAutoloading($appId, $basedir); |
|
| 133 | + |
|
| 134 | + //install the database |
|
| 135 | + if(is_file($basedir.'/appinfo/database.xml')) { |
|
| 136 | + if (\OC::$server->getAppConfig()->getValue($info['id'], 'installed_version') === null) { |
|
| 137 | + OC_DB::createDbFromStructure($basedir.'/appinfo/database.xml'); |
|
| 138 | + } else { |
|
| 139 | + OC_DB::updateDbFromStructure($basedir.'/appinfo/database.xml'); |
|
| 140 | + } |
|
| 141 | + } else { |
|
| 142 | + $ms = new \OC\DB\MigrationService($info['id'], \OC::$server->getDatabaseConnection()); |
|
| 143 | + $ms->migrate(); |
|
| 144 | + } |
|
| 145 | + |
|
| 146 | + \OC_App::setupBackgroundJobs($info['background-jobs']); |
|
| 147 | + if(isset($info['settings']) && is_array($info['settings'])) { |
|
| 148 | + \OC::$server->getSettingsManager()->setupSettings($info['settings']); |
|
| 149 | + } |
|
| 150 | + |
|
| 151 | + //run appinfo/install.php |
|
| 152 | + if((!isset($data['noinstall']) or $data['noinstall']==false)) { |
|
| 153 | + self::includeAppScript($basedir . '/appinfo/install.php'); |
|
| 154 | + } |
|
| 155 | + |
|
| 156 | + $appData = OC_App::getAppInfo($appId); |
|
| 157 | + OC_App::executeRepairSteps($appId, $appData['repair-steps']['install']); |
|
| 158 | + |
|
| 159 | + //set the installed version |
|
| 160 | + \OC::$server->getConfig()->setAppValue($info['id'], 'installed_version', OC_App::getAppVersion($info['id'], false)); |
|
| 161 | + \OC::$server->getConfig()->setAppValue($info['id'], 'enabled', 'no'); |
|
| 162 | + |
|
| 163 | + //set remote/public handlers |
|
| 164 | + foreach($info['remote'] as $name=>$path) { |
|
| 165 | + \OC::$server->getConfig()->setAppValue('core', 'remote_'.$name, $info['id'].'/'.$path); |
|
| 166 | + } |
|
| 167 | + foreach($info['public'] as $name=>$path) { |
|
| 168 | + \OC::$server->getConfig()->setAppValue('core', 'public_'.$name, $info['id'].'/'.$path); |
|
| 169 | + } |
|
| 170 | + |
|
| 171 | + OC_App::setAppTypes($info['id']); |
|
| 172 | + |
|
| 173 | + return $info['id']; |
|
| 174 | + } |
|
| 175 | + |
|
| 176 | + /** |
|
| 177 | + * @brief checks whether or not an app is installed |
|
| 178 | + * @param string $app app |
|
| 179 | + * @returns bool |
|
| 180 | + * |
|
| 181 | + * Checks whether or not an app is installed, i.e. registered in apps table. |
|
| 182 | + */ |
|
| 183 | + public static function isInstalled( $app ) { |
|
| 184 | + return (\OC::$server->getConfig()->getAppValue($app, "installed_version", null) !== null); |
|
| 185 | + } |
|
| 186 | + |
|
| 187 | + /** |
|
| 188 | + * Updates the specified app from the appstore |
|
| 189 | + * |
|
| 190 | + * @param string $appId |
|
| 191 | + * @return bool |
|
| 192 | + */ |
|
| 193 | + public function updateAppstoreApp($appId) { |
|
| 194 | + if($this->isUpdateAvailable($appId)) { |
|
| 195 | + try { |
|
| 196 | + $this->downloadApp($appId); |
|
| 197 | + } catch (\Exception $e) { |
|
| 198 | + $this->logger->error($e->getMessage(), ['app' => 'core']); |
|
| 199 | + return false; |
|
| 200 | + } |
|
| 201 | + return OC_App::updateApp($appId); |
|
| 202 | + } |
|
| 203 | + |
|
| 204 | + return false; |
|
| 205 | + } |
|
| 206 | + |
|
| 207 | + /** |
|
| 208 | + * Downloads an app and puts it into the app directory |
|
| 209 | + * |
|
| 210 | + * @param string $appId |
|
| 211 | + * |
|
| 212 | + * @throws \Exception If the installation was not successful |
|
| 213 | + */ |
|
| 214 | + public function downloadApp($appId) { |
|
| 215 | + $appId = strtolower($appId); |
|
| 216 | + |
|
| 217 | + $apps = $this->appFetcher->get(); |
|
| 218 | + foreach($apps as $app) { |
|
| 219 | + if($app['id'] === $appId) { |
|
| 220 | + // Load the certificate |
|
| 221 | + $certificate = new X509(); |
|
| 222 | + $certificate->loadCA(file_get_contents(__DIR__ . '/../../resources/codesigning/root.crt')); |
|
| 223 | + $loadedCertificate = $certificate->loadX509($app['certificate']); |
|
| 224 | + |
|
| 225 | + // Verify if the certificate has been revoked |
|
| 226 | + $crl = new X509(); |
|
| 227 | + $crl->loadCA(file_get_contents(__DIR__ . '/../../resources/codesigning/root.crt')); |
|
| 228 | + $crl->loadCRL(file_get_contents(__DIR__ . '/../../resources/codesigning/root.crl')); |
|
| 229 | + if($crl->validateSignature() !== true) { |
|
| 230 | + throw new \Exception('Could not validate CRL signature'); |
|
| 231 | + } |
|
| 232 | + $csn = $loadedCertificate['tbsCertificate']['serialNumber']->toString(); |
|
| 233 | + $revoked = $crl->getRevoked($csn); |
|
| 234 | + if ($revoked !== false) { |
|
| 235 | + throw new \Exception( |
|
| 236 | + sprintf( |
|
| 237 | + 'Certificate "%s" has been revoked', |
|
| 238 | + $csn |
|
| 239 | + ) |
|
| 240 | + ); |
|
| 241 | + } |
|
| 242 | + |
|
| 243 | + // Verify if the certificate has been issued by the Nextcloud Code Authority CA |
|
| 244 | + if($certificate->validateSignature() !== true) { |
|
| 245 | + throw new \Exception( |
|
| 246 | + sprintf( |
|
| 247 | + 'App with id %s has a certificate not issued by a trusted Code Signing Authority', |
|
| 248 | + $appId |
|
| 249 | + ) |
|
| 250 | + ); |
|
| 251 | + } |
|
| 252 | + |
|
| 253 | + // Verify if the certificate is issued for the requested app id |
|
| 254 | + $certInfo = openssl_x509_parse($app['certificate']); |
|
| 255 | + if(!isset($certInfo['subject']['CN'])) { |
|
| 256 | + throw new \Exception( |
|
| 257 | + sprintf( |
|
| 258 | + 'App with id %s has a cert with no CN', |
|
| 259 | + $appId |
|
| 260 | + ) |
|
| 261 | + ); |
|
| 262 | + } |
|
| 263 | + if($certInfo['subject']['CN'] !== $appId) { |
|
| 264 | + throw new \Exception( |
|
| 265 | + sprintf( |
|
| 266 | + 'App with id %s has a cert issued to %s', |
|
| 267 | + $appId, |
|
| 268 | + $certInfo['subject']['CN'] |
|
| 269 | + ) |
|
| 270 | + ); |
|
| 271 | + } |
|
| 272 | + |
|
| 273 | + // Download the release |
|
| 274 | + $tempFile = $this->tempManager->getTemporaryFile('.tar.gz'); |
|
| 275 | + $client = $this->clientService->newClient(); |
|
| 276 | + $client->get($app['releases'][0]['download'], ['save_to' => $tempFile]); |
|
| 277 | + |
|
| 278 | + // Check if the signature actually matches the downloaded content |
|
| 279 | + $certificate = openssl_get_publickey($app['certificate']); |
|
| 280 | + $verified = (bool)openssl_verify(file_get_contents($tempFile), base64_decode($app['releases'][0]['signature']), $certificate, OPENSSL_ALGO_SHA512); |
|
| 281 | + openssl_free_key($certificate); |
|
| 282 | + |
|
| 283 | + if($verified === true) { |
|
| 284 | + // Seems to match, let's proceed |
|
| 285 | + $extractDir = $this->tempManager->getTemporaryFolder(); |
|
| 286 | + $archive = new TAR($tempFile); |
|
| 287 | + |
|
| 288 | + if($archive) { |
|
| 289 | + if (!$archive->extract($extractDir)) { |
|
| 290 | + throw new \Exception( |
|
| 291 | + sprintf( |
|
| 292 | + 'Could not extract app %s', |
|
| 293 | + $appId |
|
| 294 | + ) |
|
| 295 | + ); |
|
| 296 | + } |
|
| 297 | + $allFiles = scandir($extractDir); |
|
| 298 | + $folders = array_diff($allFiles, ['.', '..']); |
|
| 299 | + $folders = array_values($folders); |
|
| 300 | + |
|
| 301 | + if(count($folders) > 1) { |
|
| 302 | + throw new \Exception( |
|
| 303 | + sprintf( |
|
| 304 | + 'Extracted app %s has more than 1 folder', |
|
| 305 | + $appId |
|
| 306 | + ) |
|
| 307 | + ); |
|
| 308 | + } |
|
| 309 | + |
|
| 310 | + // Check if appinfo/info.xml has the same app ID as well |
|
| 311 | + $loadEntities = libxml_disable_entity_loader(false); |
|
| 312 | + $xml = simplexml_load_file($extractDir . '/' . $folders[0] . '/appinfo/info.xml'); |
|
| 313 | + libxml_disable_entity_loader($loadEntities); |
|
| 314 | + if((string)$xml->id !== $appId) { |
|
| 315 | + throw new \Exception( |
|
| 316 | + sprintf( |
|
| 317 | + 'App for id %s has a wrong app ID in info.xml: %s', |
|
| 318 | + $appId, |
|
| 319 | + (string)$xml->id |
|
| 320 | + ) |
|
| 321 | + ); |
|
| 322 | + } |
|
| 323 | + |
|
| 324 | + // Check if the version is lower than before |
|
| 325 | + $currentVersion = OC_App::getAppVersion($appId); |
|
| 326 | + $newVersion = (string)$xml->version; |
|
| 327 | + if(version_compare($currentVersion, $newVersion) === 1) { |
|
| 328 | + throw new \Exception( |
|
| 329 | + sprintf( |
|
| 330 | + 'App for id %s has version %s and tried to update to lower version %s', |
|
| 331 | + $appId, |
|
| 332 | + $currentVersion, |
|
| 333 | + $newVersion |
|
| 334 | + ) |
|
| 335 | + ); |
|
| 336 | + } |
|
| 337 | + |
|
| 338 | + $baseDir = OC_App::getInstallPath() . '/' . $appId; |
|
| 339 | + // Remove old app with the ID if existent |
|
| 340 | + OC_Helper::rmdirr($baseDir); |
|
| 341 | + // Move to app folder |
|
| 342 | + if(@mkdir($baseDir)) { |
|
| 343 | + $extractDir .= '/' . $folders[0]; |
|
| 344 | + OC_Helper::copyr($extractDir, $baseDir); |
|
| 345 | + } |
|
| 346 | + OC_Helper::copyr($extractDir, $baseDir); |
|
| 347 | + OC_Helper::rmdirr($extractDir); |
|
| 348 | + return; |
|
| 349 | + } else { |
|
| 350 | + throw new \Exception( |
|
| 351 | + sprintf( |
|
| 352 | + 'Could not extract app with ID %s to %s', |
|
| 353 | + $appId, |
|
| 354 | + $extractDir |
|
| 355 | + ) |
|
| 356 | + ); |
|
| 357 | + } |
|
| 358 | + } else { |
|
| 359 | + // Signature does not match |
|
| 360 | + throw new \Exception( |
|
| 361 | + sprintf( |
|
| 362 | + 'App with id %s has invalid signature', |
|
| 363 | + $appId |
|
| 364 | + ) |
|
| 365 | + ); |
|
| 366 | + } |
|
| 367 | + } |
|
| 368 | + } |
|
| 369 | + |
|
| 370 | + throw new \Exception( |
|
| 371 | + sprintf( |
|
| 372 | + 'Could not download app %s', |
|
| 373 | + $appId |
|
| 374 | + ) |
|
| 375 | + ); |
|
| 376 | + } |
|
| 377 | + |
|
| 378 | + /** |
|
| 379 | + * Check if an update for the app is available |
|
| 380 | + * |
|
| 381 | + * @param string $appId |
|
| 382 | + * @return string|false false or the version number of the update |
|
| 383 | + */ |
|
| 384 | + public function isUpdateAvailable($appId) { |
|
| 385 | + if ($this->isInstanceReadyForUpdates === null) { |
|
| 386 | + $installPath = OC_App::getInstallPath(); |
|
| 387 | + if ($installPath === false || $installPath === null) { |
|
| 388 | + $this->isInstanceReadyForUpdates = false; |
|
| 389 | + } else { |
|
| 390 | + $this->isInstanceReadyForUpdates = true; |
|
| 391 | + } |
|
| 392 | + } |
|
| 393 | + |
|
| 394 | + if ($this->isInstanceReadyForUpdates === false) { |
|
| 395 | + return false; |
|
| 396 | + } |
|
| 397 | + |
|
| 398 | + if ($this->apps === null) { |
|
| 399 | + $apps = $this->appFetcher->get(); |
|
| 400 | + } |
|
| 401 | + |
|
| 402 | + foreach($apps as $app) { |
|
| 403 | + if($app['id'] === $appId) { |
|
| 404 | + $currentVersion = OC_App::getAppVersion($appId); |
|
| 405 | + $newestVersion = $app['releases'][0]['version']; |
|
| 406 | + if (version_compare($newestVersion, $currentVersion, '>')) { |
|
| 407 | + return $newestVersion; |
|
| 408 | + } else { |
|
| 409 | + return false; |
|
| 410 | + } |
|
| 411 | + } |
|
| 412 | + } |
|
| 413 | + |
|
| 414 | + return false; |
|
| 415 | + } |
|
| 416 | + |
|
| 417 | + /** |
|
| 418 | + * Check if app is already downloaded |
|
| 419 | + * @param string $name name of the application to remove |
|
| 420 | + * @return boolean |
|
| 421 | + * |
|
| 422 | + * The function will check if the app is already downloaded in the apps repository |
|
| 423 | + */ |
|
| 424 | + public function isDownloaded($name) { |
|
| 425 | + foreach(\OC::$APPSROOTS as $dir) { |
|
| 426 | + $dirToTest = $dir['path']; |
|
| 427 | + $dirToTest .= '/'; |
|
| 428 | + $dirToTest .= $name; |
|
| 429 | + $dirToTest .= '/'; |
|
| 430 | + |
|
| 431 | + if (is_dir($dirToTest)) { |
|
| 432 | + return true; |
|
| 433 | + } |
|
| 434 | + } |
|
| 435 | + |
|
| 436 | + return false; |
|
| 437 | + } |
|
| 438 | + |
|
| 439 | + /** |
|
| 440 | + * Removes an app |
|
| 441 | + * @param string $appId ID of the application to remove |
|
| 442 | + * @return boolean |
|
| 443 | + * |
|
| 444 | + * |
|
| 445 | + * This function works as follows |
|
| 446 | + * -# call uninstall repair steps |
|
| 447 | + * -# removing the files |
|
| 448 | + * |
|
| 449 | + * The function will not delete preferences, tables and the configuration, |
|
| 450 | + * this has to be done by the function oc_app_uninstall(). |
|
| 451 | + */ |
|
| 452 | + public function removeApp($appId) { |
|
| 453 | + if($this->isDownloaded( $appId )) { |
|
| 454 | + $appDir = OC_App::getInstallPath() . '/' . $appId; |
|
| 455 | + OC_Helper::rmdirr($appDir); |
|
| 456 | + return true; |
|
| 457 | + }else{ |
|
| 458 | + \OCP\Util::writeLog('core', 'can\'t remove app '.$appId.'. It is not installed.', \OCP\Util::ERROR); |
|
| 459 | + |
|
| 460 | + return false; |
|
| 461 | + } |
|
| 462 | + |
|
| 463 | + } |
|
| 464 | + |
|
| 465 | + /** |
|
| 466 | + * Installs the app within the bundle and marks the bundle as installed |
|
| 467 | + * |
|
| 468 | + * @param Bundle $bundle |
|
| 469 | + * @throws \Exception If app could not get installed |
|
| 470 | + */ |
|
| 471 | + public function installAppBundle(Bundle $bundle) { |
|
| 472 | + $appIds = $bundle->getAppIdentifiers(); |
|
| 473 | + foreach($appIds as $appId) { |
|
| 474 | + if(!$this->isDownloaded($appId)) { |
|
| 475 | + $this->downloadApp($appId); |
|
| 476 | + } |
|
| 477 | + $this->installApp($appId); |
|
| 478 | + $app = new OC_App(); |
|
| 479 | + $app->enable($appId); |
|
| 480 | + } |
|
| 481 | + $bundles = json_decode($this->config->getAppValue('core', 'installed.bundles', json_encode([])), true); |
|
| 482 | + $bundles[] = $bundle->getIdentifier(); |
|
| 483 | + $this->config->setAppValue('core', 'installed.bundles', json_encode($bundles)); |
|
| 484 | + } |
|
| 485 | + |
|
| 486 | + /** |
|
| 487 | + * Installs shipped apps |
|
| 488 | + * |
|
| 489 | + * This function installs all apps found in the 'apps' directory that should be enabled by default; |
|
| 490 | + * @param bool $softErrors When updating we ignore errors and simply log them, better to have a |
|
| 491 | + * working ownCloud at the end instead of an aborted update. |
|
| 492 | + * @return array Array of error messages (appid => Exception) |
|
| 493 | + */ |
|
| 494 | + public static function installShippedApps($softErrors = false) { |
|
| 495 | + $errors = []; |
|
| 496 | + foreach(\OC::$APPSROOTS as $app_dir) { |
|
| 497 | + if($dir = opendir( $app_dir['path'] )) { |
|
| 498 | + while( false !== ( $filename = readdir( $dir ))) { |
|
| 499 | + if( substr( $filename, 0, 1 ) != '.' and is_dir($app_dir['path']."/$filename") ) { |
|
| 500 | + if( file_exists( $app_dir['path']."/$filename/appinfo/info.xml" )) { |
|
| 501 | + if(!Installer::isInstalled($filename)) { |
|
| 502 | + $info=OC_App::getAppInfo($filename); |
|
| 503 | + $enabled = isset($info['default_enable']); |
|
| 504 | + if (($enabled || in_array($filename, \OC::$server->getAppManager()->getAlwaysEnabledApps())) |
|
| 505 | + && \OC::$server->getConfig()->getAppValue($filename, 'enabled') !== 'no') { |
|
| 506 | + if ($softErrors) { |
|
| 507 | + try { |
|
| 508 | + Installer::installShippedApp($filename); |
|
| 509 | + } catch (HintException $e) { |
|
| 510 | + if ($e->getPrevious() instanceof TableExistsException) { |
|
| 511 | + $errors[$filename] = $e; |
|
| 512 | + continue; |
|
| 513 | + } |
|
| 514 | + throw $e; |
|
| 515 | + } |
|
| 516 | + } else { |
|
| 517 | + Installer::installShippedApp($filename); |
|
| 518 | + } |
|
| 519 | + \OC::$server->getConfig()->setAppValue($filename, 'enabled', 'yes'); |
|
| 520 | + } |
|
| 521 | + } |
|
| 522 | + } |
|
| 523 | + } |
|
| 524 | + } |
|
| 525 | + closedir( $dir ); |
|
| 526 | + } |
|
| 527 | + } |
|
| 528 | + |
|
| 529 | + return $errors; |
|
| 530 | + } |
|
| 531 | + |
|
| 532 | + /** |
|
| 533 | + * install an app already placed in the app folder |
|
| 534 | + * @param string $app id of the app to install |
|
| 535 | + * @return integer |
|
| 536 | + */ |
|
| 537 | + public static function installShippedApp($app) { |
|
| 538 | + //install the database |
|
| 539 | + $appPath = OC_App::getAppPath($app); |
|
| 540 | + \OC_App::registerAutoloading($app, $appPath); |
|
| 541 | + |
|
| 542 | + if(is_file("$appPath/appinfo/database.xml")) { |
|
| 543 | + try { |
|
| 544 | + OC_DB::createDbFromStructure("$appPath/appinfo/database.xml"); |
|
| 545 | + } catch (TableExistsException $e) { |
|
| 546 | + throw new HintException( |
|
| 547 | + 'Failed to enable app ' . $app, |
|
| 548 | + 'Please ask for help via one of our <a href="https://nextcloud.com/support/" target="_blank" rel="noreferrer noopener">support channels</a>.', |
|
| 549 | + 0, $e |
|
| 550 | + ); |
|
| 551 | + } |
|
| 552 | + } else { |
|
| 553 | + $ms = new \OC\DB\MigrationService($app, \OC::$server->getDatabaseConnection()); |
|
| 554 | + $ms->migrate(); |
|
| 555 | + } |
|
| 556 | + |
|
| 557 | + //run appinfo/install.php |
|
| 558 | + self::includeAppScript("$appPath/appinfo/install.php"); |
|
| 559 | + |
|
| 560 | + $info = OC_App::getAppInfo($app); |
|
| 561 | + if (is_null($info)) { |
|
| 562 | + return false; |
|
| 563 | + } |
|
| 564 | + \OC_App::setupBackgroundJobs($info['background-jobs']); |
|
| 565 | + |
|
| 566 | + OC_App::executeRepairSteps($app, $info['repair-steps']['install']); |
|
| 567 | + |
|
| 568 | + $config = \OC::$server->getConfig(); |
|
| 569 | + |
|
| 570 | + $config->setAppValue($app, 'installed_version', OC_App::getAppVersion($app)); |
|
| 571 | + if (array_key_exists('ocsid', $info)) { |
|
| 572 | + $config->setAppValue($app, 'ocsid', $info['ocsid']); |
|
| 573 | + } |
|
| 574 | + |
|
| 575 | + //set remote/public handlers |
|
| 576 | + foreach($info['remote'] as $name=>$path) { |
|
| 577 | + $config->setAppValue('core', 'remote_'.$name, $app.'/'.$path); |
|
| 578 | + } |
|
| 579 | + foreach($info['public'] as $name=>$path) { |
|
| 580 | + $config->setAppValue('core', 'public_'.$name, $app.'/'.$path); |
|
| 581 | + } |
|
| 582 | + |
|
| 583 | + OC_App::setAppTypes($info['id']); |
|
| 584 | + |
|
| 585 | + if(isset($info['settings']) && is_array($info['settings'])) { |
|
| 586 | + // requires that autoloading was registered for the app, |
|
| 587 | + // as happens before running the install.php some lines above |
|
| 588 | + \OC::$server->getSettingsManager()->setupSettings($info['settings']); |
|
| 589 | + } |
|
| 590 | + |
|
| 591 | + return $info['id']; |
|
| 592 | + } |
|
| 593 | + |
|
| 594 | + /** |
|
| 595 | + * @param string $script |
|
| 596 | + */ |
|
| 597 | + private static function includeAppScript($script) { |
|
| 598 | + if ( file_exists($script) ){ |
|
| 599 | + include $script; |
|
| 600 | + } |
|
| 601 | + } |
|
| 602 | 602 | } |
@@ -100,7 +100,7 @@ discard block |
||
| 100 | 100 | */ |
| 101 | 101 | public function installApp($appId) { |
| 102 | 102 | $app = \OC_App::findAppInDirectories($appId); |
| 103 | - if($app === false) { |
|
| 103 | + if ($app === false) { |
|
| 104 | 104 | throw new \Exception('App not found in any app directory'); |
| 105 | 105 | } |
| 106 | 106 | |
@@ -109,7 +109,7 @@ discard block |
||
| 109 | 109 | |
| 110 | 110 | $l = \OC::$server->getL10N('core'); |
| 111 | 111 | |
| 112 | - if(!is_array($info)) { |
|
| 112 | + if (!is_array($info)) { |
|
| 113 | 113 | throw new \Exception( |
| 114 | 114 | $l->t('App "%s" cannot be installed because appinfo file cannot be read.', |
| 115 | 115 | [$info['name']] |
@@ -132,7 +132,7 @@ discard block |
||
| 132 | 132 | \OC_App::registerAutoloading($appId, $basedir); |
| 133 | 133 | |
| 134 | 134 | //install the database |
| 135 | - if(is_file($basedir.'/appinfo/database.xml')) { |
|
| 135 | + if (is_file($basedir.'/appinfo/database.xml')) { |
|
| 136 | 136 | if (\OC::$server->getAppConfig()->getValue($info['id'], 'installed_version') === null) { |
| 137 | 137 | OC_DB::createDbFromStructure($basedir.'/appinfo/database.xml'); |
| 138 | 138 | } else { |
@@ -144,13 +144,13 @@ discard block |
||
| 144 | 144 | } |
| 145 | 145 | |
| 146 | 146 | \OC_App::setupBackgroundJobs($info['background-jobs']); |
| 147 | - if(isset($info['settings']) && is_array($info['settings'])) { |
|
| 147 | + if (isset($info['settings']) && is_array($info['settings'])) { |
|
| 148 | 148 | \OC::$server->getSettingsManager()->setupSettings($info['settings']); |
| 149 | 149 | } |
| 150 | 150 | |
| 151 | 151 | //run appinfo/install.php |
| 152 | - if((!isset($data['noinstall']) or $data['noinstall']==false)) { |
|
| 153 | - self::includeAppScript($basedir . '/appinfo/install.php'); |
|
| 152 | + if ((!isset($data['noinstall']) or $data['noinstall'] == false)) { |
|
| 153 | + self::includeAppScript($basedir.'/appinfo/install.php'); |
|
| 154 | 154 | } |
| 155 | 155 | |
| 156 | 156 | $appData = OC_App::getAppInfo($appId); |
@@ -161,10 +161,10 @@ discard block |
||
| 161 | 161 | \OC::$server->getConfig()->setAppValue($info['id'], 'enabled', 'no'); |
| 162 | 162 | |
| 163 | 163 | //set remote/public handlers |
| 164 | - foreach($info['remote'] as $name=>$path) { |
|
| 164 | + foreach ($info['remote'] as $name=>$path) { |
|
| 165 | 165 | \OC::$server->getConfig()->setAppValue('core', 'remote_'.$name, $info['id'].'/'.$path); |
| 166 | 166 | } |
| 167 | - foreach($info['public'] as $name=>$path) { |
|
| 167 | + foreach ($info['public'] as $name=>$path) { |
|
| 168 | 168 | \OC::$server->getConfig()->setAppValue('core', 'public_'.$name, $info['id'].'/'.$path); |
| 169 | 169 | } |
| 170 | 170 | |
@@ -180,7 +180,7 @@ discard block |
||
| 180 | 180 | * |
| 181 | 181 | * Checks whether or not an app is installed, i.e. registered in apps table. |
| 182 | 182 | */ |
| 183 | - public static function isInstalled( $app ) { |
|
| 183 | + public static function isInstalled($app) { |
|
| 184 | 184 | return (\OC::$server->getConfig()->getAppValue($app, "installed_version", null) !== null); |
| 185 | 185 | } |
| 186 | 186 | |
@@ -191,7 +191,7 @@ discard block |
||
| 191 | 191 | * @return bool |
| 192 | 192 | */ |
| 193 | 193 | public function updateAppstoreApp($appId) { |
| 194 | - if($this->isUpdateAvailable($appId)) { |
|
| 194 | + if ($this->isUpdateAvailable($appId)) { |
|
| 195 | 195 | try { |
| 196 | 196 | $this->downloadApp($appId); |
| 197 | 197 | } catch (\Exception $e) { |
@@ -215,18 +215,18 @@ discard block |
||
| 215 | 215 | $appId = strtolower($appId); |
| 216 | 216 | |
| 217 | 217 | $apps = $this->appFetcher->get(); |
| 218 | - foreach($apps as $app) { |
|
| 219 | - if($app['id'] === $appId) { |
|
| 218 | + foreach ($apps as $app) { |
|
| 219 | + if ($app['id'] === $appId) { |
|
| 220 | 220 | // Load the certificate |
| 221 | 221 | $certificate = new X509(); |
| 222 | - $certificate->loadCA(file_get_contents(__DIR__ . '/../../resources/codesigning/root.crt')); |
|
| 222 | + $certificate->loadCA(file_get_contents(__DIR__.'/../../resources/codesigning/root.crt')); |
|
| 223 | 223 | $loadedCertificate = $certificate->loadX509($app['certificate']); |
| 224 | 224 | |
| 225 | 225 | // Verify if the certificate has been revoked |
| 226 | 226 | $crl = new X509(); |
| 227 | - $crl->loadCA(file_get_contents(__DIR__ . '/../../resources/codesigning/root.crt')); |
|
| 228 | - $crl->loadCRL(file_get_contents(__DIR__ . '/../../resources/codesigning/root.crl')); |
|
| 229 | - if($crl->validateSignature() !== true) { |
|
| 227 | + $crl->loadCA(file_get_contents(__DIR__.'/../../resources/codesigning/root.crt')); |
|
| 228 | + $crl->loadCRL(file_get_contents(__DIR__.'/../../resources/codesigning/root.crl')); |
|
| 229 | + if ($crl->validateSignature() !== true) { |
|
| 230 | 230 | throw new \Exception('Could not validate CRL signature'); |
| 231 | 231 | } |
| 232 | 232 | $csn = $loadedCertificate['tbsCertificate']['serialNumber']->toString(); |
@@ -241,7 +241,7 @@ discard block |
||
| 241 | 241 | } |
| 242 | 242 | |
| 243 | 243 | // Verify if the certificate has been issued by the Nextcloud Code Authority CA |
| 244 | - if($certificate->validateSignature() !== true) { |
|
| 244 | + if ($certificate->validateSignature() !== true) { |
|
| 245 | 245 | throw new \Exception( |
| 246 | 246 | sprintf( |
| 247 | 247 | 'App with id %s has a certificate not issued by a trusted Code Signing Authority', |
@@ -252,7 +252,7 @@ discard block |
||
| 252 | 252 | |
| 253 | 253 | // Verify if the certificate is issued for the requested app id |
| 254 | 254 | $certInfo = openssl_x509_parse($app['certificate']); |
| 255 | - if(!isset($certInfo['subject']['CN'])) { |
|
| 255 | + if (!isset($certInfo['subject']['CN'])) { |
|
| 256 | 256 | throw new \Exception( |
| 257 | 257 | sprintf( |
| 258 | 258 | 'App with id %s has a cert with no CN', |
@@ -260,7 +260,7 @@ discard block |
||
| 260 | 260 | ) |
| 261 | 261 | ); |
| 262 | 262 | } |
| 263 | - if($certInfo['subject']['CN'] !== $appId) { |
|
| 263 | + if ($certInfo['subject']['CN'] !== $appId) { |
|
| 264 | 264 | throw new \Exception( |
| 265 | 265 | sprintf( |
| 266 | 266 | 'App with id %s has a cert issued to %s', |
@@ -277,15 +277,15 @@ discard block |
||
| 277 | 277 | |
| 278 | 278 | // Check if the signature actually matches the downloaded content |
| 279 | 279 | $certificate = openssl_get_publickey($app['certificate']); |
| 280 | - $verified = (bool)openssl_verify(file_get_contents($tempFile), base64_decode($app['releases'][0]['signature']), $certificate, OPENSSL_ALGO_SHA512); |
|
| 280 | + $verified = (bool) openssl_verify(file_get_contents($tempFile), base64_decode($app['releases'][0]['signature']), $certificate, OPENSSL_ALGO_SHA512); |
|
| 281 | 281 | openssl_free_key($certificate); |
| 282 | 282 | |
| 283 | - if($verified === true) { |
|
| 283 | + if ($verified === true) { |
|
| 284 | 284 | // Seems to match, let's proceed |
| 285 | 285 | $extractDir = $this->tempManager->getTemporaryFolder(); |
| 286 | 286 | $archive = new TAR($tempFile); |
| 287 | 287 | |
| 288 | - if($archive) { |
|
| 288 | + if ($archive) { |
|
| 289 | 289 | if (!$archive->extract($extractDir)) { |
| 290 | 290 | throw new \Exception( |
| 291 | 291 | sprintf( |
@@ -298,7 +298,7 @@ discard block |
||
| 298 | 298 | $folders = array_diff($allFiles, ['.', '..']); |
| 299 | 299 | $folders = array_values($folders); |
| 300 | 300 | |
| 301 | - if(count($folders) > 1) { |
|
| 301 | + if (count($folders) > 1) { |
|
| 302 | 302 | throw new \Exception( |
| 303 | 303 | sprintf( |
| 304 | 304 | 'Extracted app %s has more than 1 folder', |
@@ -309,22 +309,22 @@ discard block |
||
| 309 | 309 | |
| 310 | 310 | // Check if appinfo/info.xml has the same app ID as well |
| 311 | 311 | $loadEntities = libxml_disable_entity_loader(false); |
| 312 | - $xml = simplexml_load_file($extractDir . '/' . $folders[0] . '/appinfo/info.xml'); |
|
| 312 | + $xml = simplexml_load_file($extractDir.'/'.$folders[0].'/appinfo/info.xml'); |
|
| 313 | 313 | libxml_disable_entity_loader($loadEntities); |
| 314 | - if((string)$xml->id !== $appId) { |
|
| 314 | + if ((string) $xml->id !== $appId) { |
|
| 315 | 315 | throw new \Exception( |
| 316 | 316 | sprintf( |
| 317 | 317 | 'App for id %s has a wrong app ID in info.xml: %s', |
| 318 | 318 | $appId, |
| 319 | - (string)$xml->id |
|
| 319 | + (string) $xml->id |
|
| 320 | 320 | ) |
| 321 | 321 | ); |
| 322 | 322 | } |
| 323 | 323 | |
| 324 | 324 | // Check if the version is lower than before |
| 325 | 325 | $currentVersion = OC_App::getAppVersion($appId); |
| 326 | - $newVersion = (string)$xml->version; |
|
| 327 | - if(version_compare($currentVersion, $newVersion) === 1) { |
|
| 326 | + $newVersion = (string) $xml->version; |
|
| 327 | + if (version_compare($currentVersion, $newVersion) === 1) { |
|
| 328 | 328 | throw new \Exception( |
| 329 | 329 | sprintf( |
| 330 | 330 | 'App for id %s has version %s and tried to update to lower version %s', |
@@ -335,12 +335,12 @@ discard block |
||
| 335 | 335 | ); |
| 336 | 336 | } |
| 337 | 337 | |
| 338 | - $baseDir = OC_App::getInstallPath() . '/' . $appId; |
|
| 338 | + $baseDir = OC_App::getInstallPath().'/'.$appId; |
|
| 339 | 339 | // Remove old app with the ID if existent |
| 340 | 340 | OC_Helper::rmdirr($baseDir); |
| 341 | 341 | // Move to app folder |
| 342 | - if(@mkdir($baseDir)) { |
|
| 343 | - $extractDir .= '/' . $folders[0]; |
|
| 342 | + if (@mkdir($baseDir)) { |
|
| 343 | + $extractDir .= '/'.$folders[0]; |
|
| 344 | 344 | OC_Helper::copyr($extractDir, $baseDir); |
| 345 | 345 | } |
| 346 | 346 | OC_Helper::copyr($extractDir, $baseDir); |
@@ -399,8 +399,8 @@ discard block |
||
| 399 | 399 | $apps = $this->appFetcher->get(); |
| 400 | 400 | } |
| 401 | 401 | |
| 402 | - foreach($apps as $app) { |
|
| 403 | - if($app['id'] === $appId) { |
|
| 402 | + foreach ($apps as $app) { |
|
| 403 | + if ($app['id'] === $appId) { |
|
| 404 | 404 | $currentVersion = OC_App::getAppVersion($appId); |
| 405 | 405 | $newestVersion = $app['releases'][0]['version']; |
| 406 | 406 | if (version_compare($newestVersion, $currentVersion, '>')) { |
@@ -422,7 +422,7 @@ discard block |
||
| 422 | 422 | * The function will check if the app is already downloaded in the apps repository |
| 423 | 423 | */ |
| 424 | 424 | public function isDownloaded($name) { |
| 425 | - foreach(\OC::$APPSROOTS as $dir) { |
|
| 425 | + foreach (\OC::$APPSROOTS as $dir) { |
|
| 426 | 426 | $dirToTest = $dir['path']; |
| 427 | 427 | $dirToTest .= '/'; |
| 428 | 428 | $dirToTest .= $name; |
@@ -450,11 +450,11 @@ discard block |
||
| 450 | 450 | * this has to be done by the function oc_app_uninstall(). |
| 451 | 451 | */ |
| 452 | 452 | public function removeApp($appId) { |
| 453 | - if($this->isDownloaded( $appId )) { |
|
| 454 | - $appDir = OC_App::getInstallPath() . '/' . $appId; |
|
| 453 | + if ($this->isDownloaded($appId)) { |
|
| 454 | + $appDir = OC_App::getInstallPath().'/'.$appId; |
|
| 455 | 455 | OC_Helper::rmdirr($appDir); |
| 456 | 456 | return true; |
| 457 | - }else{ |
|
| 457 | + } else { |
|
| 458 | 458 | \OCP\Util::writeLog('core', 'can\'t remove app '.$appId.'. It is not installed.', \OCP\Util::ERROR); |
| 459 | 459 | |
| 460 | 460 | return false; |
@@ -470,8 +470,8 @@ discard block |
||
| 470 | 470 | */ |
| 471 | 471 | public function installAppBundle(Bundle $bundle) { |
| 472 | 472 | $appIds = $bundle->getAppIdentifiers(); |
| 473 | - foreach($appIds as $appId) { |
|
| 474 | - if(!$this->isDownloaded($appId)) { |
|
| 473 | + foreach ($appIds as $appId) { |
|
| 474 | + if (!$this->isDownloaded($appId)) { |
|
| 475 | 475 | $this->downloadApp($appId); |
| 476 | 476 | } |
| 477 | 477 | $this->installApp($appId); |
@@ -493,13 +493,13 @@ discard block |
||
| 493 | 493 | */ |
| 494 | 494 | public static function installShippedApps($softErrors = false) { |
| 495 | 495 | $errors = []; |
| 496 | - foreach(\OC::$APPSROOTS as $app_dir) { |
|
| 497 | - if($dir = opendir( $app_dir['path'] )) { |
|
| 498 | - while( false !== ( $filename = readdir( $dir ))) { |
|
| 499 | - if( substr( $filename, 0, 1 ) != '.' and is_dir($app_dir['path']."/$filename") ) { |
|
| 500 | - if( file_exists( $app_dir['path']."/$filename/appinfo/info.xml" )) { |
|
| 501 | - if(!Installer::isInstalled($filename)) { |
|
| 502 | - $info=OC_App::getAppInfo($filename); |
|
| 496 | + foreach (\OC::$APPSROOTS as $app_dir) { |
|
| 497 | + if ($dir = opendir($app_dir['path'])) { |
|
| 498 | + while (false !== ($filename = readdir($dir))) { |
|
| 499 | + if (substr($filename, 0, 1) != '.' and is_dir($app_dir['path']."/$filename")) { |
|
| 500 | + if (file_exists($app_dir['path']."/$filename/appinfo/info.xml")) { |
|
| 501 | + if (!Installer::isInstalled($filename)) { |
|
| 502 | + $info = OC_App::getAppInfo($filename); |
|
| 503 | 503 | $enabled = isset($info['default_enable']); |
| 504 | 504 | if (($enabled || in_array($filename, \OC::$server->getAppManager()->getAlwaysEnabledApps())) |
| 505 | 505 | && \OC::$server->getConfig()->getAppValue($filename, 'enabled') !== 'no') { |
@@ -522,7 +522,7 @@ discard block |
||
| 522 | 522 | } |
| 523 | 523 | } |
| 524 | 524 | } |
| 525 | - closedir( $dir ); |
|
| 525 | + closedir($dir); |
|
| 526 | 526 | } |
| 527 | 527 | } |
| 528 | 528 | |
@@ -539,12 +539,12 @@ discard block |
||
| 539 | 539 | $appPath = OC_App::getAppPath($app); |
| 540 | 540 | \OC_App::registerAutoloading($app, $appPath); |
| 541 | 541 | |
| 542 | - if(is_file("$appPath/appinfo/database.xml")) { |
|
| 542 | + if (is_file("$appPath/appinfo/database.xml")) { |
|
| 543 | 543 | try { |
| 544 | 544 | OC_DB::createDbFromStructure("$appPath/appinfo/database.xml"); |
| 545 | 545 | } catch (TableExistsException $e) { |
| 546 | 546 | throw new HintException( |
| 547 | - 'Failed to enable app ' . $app, |
|
| 547 | + 'Failed to enable app '.$app, |
|
| 548 | 548 | 'Please ask for help via one of our <a href="https://nextcloud.com/support/" target="_blank" rel="noreferrer noopener">support channels</a>.', |
| 549 | 549 | 0, $e |
| 550 | 550 | ); |
@@ -573,16 +573,16 @@ discard block |
||
| 573 | 573 | } |
| 574 | 574 | |
| 575 | 575 | //set remote/public handlers |
| 576 | - foreach($info['remote'] as $name=>$path) { |
|
| 576 | + foreach ($info['remote'] as $name=>$path) { |
|
| 577 | 577 | $config->setAppValue('core', 'remote_'.$name, $app.'/'.$path); |
| 578 | 578 | } |
| 579 | - foreach($info['public'] as $name=>$path) { |
|
| 579 | + foreach ($info['public'] as $name=>$path) { |
|
| 580 | 580 | $config->setAppValue('core', 'public_'.$name, $app.'/'.$path); |
| 581 | 581 | } |
| 582 | 582 | |
| 583 | 583 | OC_App::setAppTypes($info['id']); |
| 584 | 584 | |
| 585 | - if(isset($info['settings']) && is_array($info['settings'])) { |
|
| 585 | + if (isset($info['settings']) && is_array($info['settings'])) { |
|
| 586 | 586 | // requires that autoloading was registered for the app, |
| 587 | 587 | // as happens before running the install.php some lines above |
| 588 | 588 | \OC::$server->getSettingsManager()->setupSettings($info['settings']); |
@@ -595,7 +595,7 @@ discard block |
||
| 595 | 595 | * @param string $script |
| 596 | 596 | */ |
| 597 | 597 | private static function includeAppScript($script) { |
| 598 | - if ( file_exists($script) ){ |
|
| 598 | + if (file_exists($script)) { |
|
| 599 | 599 | include $script; |
| 600 | 600 | } |
| 601 | 601 | } |
@@ -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 | } |