diff options
author | Robin Appelman <robin@icewind.nl> | 2018-08-06 20:15:44 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-08-06 20:15:44 +0300 |
commit | d4b6f0393e2d786641bfb44fcee7f92c26125140 (patch) | |
tree | f42448ccf87d6a339ae2c517104e57032fa8f8c4 | |
parent | b8ec476886210a797a8601e9a719708bb8733242 (diff) | |
parent | 76e7b9796392350223c52bcfd483ad481f68497c (diff) |
Merge pull request #164 from nextcloud/table-renamev1.3.0
rename applicable folder to comply with oracle limitations
-rw-r--r-- | appinfo/app.php | 4 | ||||
-rw-r--r-- | appinfo/database.xml | 89 | ||||
-rw-r--r-- | appinfo/info.xml | 18 | ||||
-rw-r--r-- | lib/Folder/FolderManager.php | 12 | ||||
-rw-r--r-- | lib/Migration/Version102020Date20180806161449.php | 65 | ||||
-rw-r--r-- | lib/Migration/Version103000Date20180806161724.php | 96 | ||||
-rw-r--r-- | tests/Folder/FolderManagerTest.php | 2 |
7 files changed, 179 insertions, 107 deletions
diff --git a/appinfo/app.php b/appinfo/app.php index 54a5711d..9e741911 100644 --- a/appinfo/app.php +++ b/appinfo/app.php @@ -9,10 +9,10 @@ $eventDispatcher = \OC::$server->getEventDispatcher(); $eventDispatcher->addListener( 'OCA\Files::loadAdditionalScripts', function () { - \OC_Util::addScript('groupfolders', 'files'); + \OCP\Util::addScript('groupfolders', 'files'); } ); $eventDispatcher->addListener('OCA\Files_Sharing::loadAdditionalScripts', function () { - \OC_Util::addScript('groupfolders', 'files'); + \OCP\Util::addScript('groupfolders', 'files'); }); diff --git a/appinfo/database.xml b/appinfo/database.xml deleted file mode 100644 index 3579e014..00000000 --- a/appinfo/database.xml +++ /dev/null @@ -1,89 +0,0 @@ -<database> - <name>*dbname*</name> - <create>true</create> - <overwrite>false</overwrite> - <charset>utf8</charset> - <table> - <name>*dbprefix*group_folders</name> - <declaration> - <field> - <name>folder_id</name> - <type>integer</type> - <default>0</default> - <notnull>true</notnull> - <autoincrement>1</autoincrement> - <length>6</length> - </field> - <field> - <name>mount_point</name> - <type>text</type> - <length>128</length> - <notnull>true</notnull> - </field> - <field> - <name>quota</name> - <type>integer</type> - <notnull>true</notnull> - <length>6</length> - <default>-3</default> - </field> - </declaration> - </table> - <table> - <name>*dbprefix*group_folders_applicable</name> - <declaration> - <field> - <name>applicable_id</name> - <type>integer</type> - <default>0</default> - <notnull>true</notnull> - <autoincrement>1</autoincrement> - <length>6</length> - </field> - <field> - <name>folder_id</name> - <type>integer</type> - <notnull>true</notnull> - <length>6</length> - </field> - <field> - <name>permissions</name> - <type>integer</type> - <length>4</length> - <notnull>true</notnull> - </field> - <field> - <name>group_id</name> - <type>text</type> - <length>64</length> - </field> - - <index> - <name>applicable_folder</name> - <field> - <name>folder_id</name> - <sorting>ascending</sorting> - </field> - </index> - <index> - <name>applicable_folder_value</name> - <field> - <name>group_id</name> - <sorting>ascending</sorting> - </field> - </index> - <index> - <name>applicable_folder_group</name> - <unique>true</unique> - <field> - <name>folder_id</name> - <sorting>ascending</sorting> - </field> - <field> - <name>group_id</name> - <sorting>ascending</sorting> - </field> - </index> - </declaration> - </table> -</database> diff --git a/appinfo/info.xml b/appinfo/info.xml index c4658bcf..fef1b5d7 100644 --- a/appinfo/info.xml +++ b/appinfo/info.xml @@ -10,13 +10,15 @@ Folders can be configured from *Group folders* in the admin settings. After a folder is created, the admin can give access to the folder to one or more groups, control their write/sharing permissions and assign a quota for the folder. Note: encrypting the contents of group folders is currently not supported.]]></description> - <licence>AGPL</licence> + <version>1.3.0</version> + <licence>agpl</licence> <author>Robin Appelman</author> - <version>1.2.2</version> + <namespace>GroupFolders</namespace> <types> <filesystem/> </types> - <namespace>GroupFolders</namespace> + + <category>files</category> <website>https://github.com/nextcloud/groupfolders</website> <bugs>https://github.com/nextcloud/groupfolders/issues</bugs> @@ -26,14 +28,12 @@ Note: encrypting the contents of group folders is currently not supported.]]></d <screenshot>https://raw.githubusercontent.com/nextcloud/groupfolders/master/screenshots/edit.png</screenshot> <screenshot>https://raw.githubusercontent.com/nextcloud/groupfolders/master/screenshots/permissions.png</screenshot> + <dependencies> + <nextcloud min-version="12" max-version="14"/> + </dependencies> + <settings> <admin>OCA\GroupFolders\Settings\Admin</admin> <admin-section>OCA\GroupFolders\Settings\Section</admin-section> </settings> - - <category>files</category> - - <dependencies> - <nextcloud min-version="12" max-version="14"/> - </dependencies> </info> diff --git a/lib/Folder/FolderManager.php b/lib/Folder/FolderManager.php index 9325d1ce..a6a779ac 100644 --- a/lib/Folder/FolderManager.php +++ b/lib/Folder/FolderManager.php @@ -122,7 +122,7 @@ class FolderManager { $query = $this->connection->getQueryBuilder(); $query->select('folder_id', 'group_id', 'permissions') - ->from('group_folders_applicable'); + ->from('group_folders_groups'); $rows = $query->execute()->fetchAll(); @@ -149,7 +149,7 @@ class FolderManager { ->from('group_folders', 'f') ->innerJoin( 'f', - 'group_folders_applicable', + 'group_folders_groups', 'a', $query->expr()->eq('f.folder_id', 'a.folder_id') ) @@ -190,7 +190,7 @@ class FolderManager { public function addApplicableGroup($folderId, $groupId) { $query = $this->connection->getQueryBuilder(); - $query->insert('group_folders_applicable') + $query->insert('group_folders_groups') ->values([ 'folder_id' => $query->createNamedParameter($folderId, IQueryBuilder::PARAM_INT), 'group_id' => $query->createNamedParameter($groupId), @@ -202,7 +202,7 @@ class FolderManager { public function removeApplicableGroup($folderId, $groupId) { $query = $this->connection->getQueryBuilder(); - $query->delete('group_folders_applicable') + $query->delete('group_folders_groups') ->where($query->expr()->eq('folder_id', $query->createNamedParameter($folderId, IQueryBuilder::PARAM_INT))) ->andWhere($query->expr()->eq('group_id', $query->createNamedParameter($groupId))); $query->execute(); @@ -211,7 +211,7 @@ class FolderManager { public function setGroupPermissions($folderId, $groupId, $permissions) { $query = $this->connection->getQueryBuilder(); - $query->update('group_folders_applicable') + $query->update('group_folders_groups') ->set('permissions', $query->createNamedParameter($permissions, IQueryBuilder::PARAM_INT)) ->where($query->expr()->eq('folder_id', $query->createNamedParameter($folderId, IQueryBuilder::PARAM_INT))) ->andWhere($query->expr()->eq('group_id', $query->createNamedParameter($groupId))); @@ -248,7 +248,7 @@ class FolderManager { public function deleteGroup($groupId) { $query = $this->connection->getQueryBuilder(); - $query->delete('group_folders_applicable') + $query->delete('group_folders_groups') ->where($query->expr()->eq('group_id', $query->createNamedParameter($groupId))); $query->execute(); } diff --git a/lib/Migration/Version102020Date20180806161449.php b/lib/Migration/Version102020Date20180806161449.php new file mode 100644 index 00000000..a7fda82d --- /dev/null +++ b/lib/Migration/Version102020Date20180806161449.php @@ -0,0 +1,65 @@ +<?php +namespace OCA\GroupFolders\Migration; + +use OCP\DB\ISchemaWrapper; +use OCP\Migration\SimpleMigrationStep; +use OCP\Migration\IOutput; + +class Version102020Date20180806161449 extends SimpleMigrationStep { + /** + * @param IOutput $output + * @param \Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` + * @param array $options + * @return null|ISchemaWrapper + * @since 13.0.0 + */ + public function changeSchema(IOutput $output, \Closure $schemaClosure, array $options) { + /** @var ISchemaWrapper $schema */ + $schema = $schemaClosure(); + + if (!$schema->hasTable('group_folders')) { + $table = $schema->createTable('group_folders'); + $table->addColumn('folder_id', 'bigint', [ + 'autoincrement' => true, + 'notnull' => true, + 'length' => 6, + ]); + $table->addColumn('mount_point', 'string', [ + 'notnull' => true, + 'length' => 128, + ]); + $table->addColumn('quota', 'bigint', [ + 'notnull' => true, + 'length' => 6, + 'default' => -3, + ]); + $table->setPrimaryKey(['folder_id']); + } + + if (!$schema->hasTable('group_folders_groups')) { + $table = $schema->createTable('group_folders_groups'); + $table->addColumn('applicable_id', 'bigint', [ + 'autoincrement' => true, + 'notnull' => true, + 'length' => 6, + ]); + $table->addColumn('folder_id', 'bigint', [ + 'notnull' => true, + 'length' => 6, + ]); + $table->addColumn('permissions', 'integer', [ + 'notnull' => true, + 'length' => 4, + ]); + $table->addColumn('group_id', 'string', [ + 'notnull' => false, + 'length' => 64, + ]); + $table->setPrimaryKey(['applicable_id']); + $table->addIndex(['folder_id'], 'group_folder'); + $table->addIndex(['group_id'], 'group_folder_value'); + $table->addUniqueIndex(['folder_id', 'group_id'], 'groups_folder_group'); + } + return $schema; + } +} diff --git a/lib/Migration/Version103000Date20180806161724.php b/lib/Migration/Version103000Date20180806161724.php new file mode 100644 index 00000000..d0e7e650 --- /dev/null +++ b/lib/Migration/Version103000Date20180806161724.php @@ -0,0 +1,96 @@ +<?php +namespace OCA\GroupFolders\Migration; + +use OCP\DB\ISchemaWrapper; +use OCP\IDBConnection; +use OCP\Migration\SimpleMigrationStep; +use OCP\Migration\IOutput; + +class Version103000Date20180806161724 extends SimpleMigrationStep { + /** @var IDBConnection */ + private $connection; + + private $applicableData = []; + + public function __construct(IDBConnection $connection) { + $this->connection = $connection; + } + + public function name(): string { + return 'rename "group_folders_applicable" to "group_folders_groups"'; + } + + public function description(): string { + return 'rename "group_folders_applicable" to fit within oracle limitations'; + } + + public function preSchemaChange(IOutput $output, \Closure $schemaClosure, array $options) { + /** @var ISchemaWrapper $schema */ + $schema = $schemaClosure(); + + // copy data + if ($schema->hasTable('group_folders_applicable')) { + $query = $this->connection->getQueryBuilder(); + $query->select(['folder_id', 'permissions', 'group_id']) + ->from('group_folders_applicable'); + $result = $query->execute(); + $this->applicableData = $result->fetchAll(\PDO::FETCH_ASSOC); + } + } + + public function changeSchema(IOutput $output, \Closure $schemaClosure, array $options) { + /** @var ISchemaWrapper $schema */ + $schema = $schemaClosure(); + + if (!$schema->hasTable('group_folders_groups')) { + $table = $schema->createTable('group_folders_groups'); + $table->addColumn('applicable_id', 'bigint', [ + 'autoincrement' => true, + 'notnull' => true, + 'length' => 6, + ]); + $table->addColumn('folder_id', 'bigint', [ + 'notnull' => true, + 'length' => 6, + ]); + $table->addColumn('permissions', 'integer', [ + 'notnull' => true, + 'length' => 4, + ]); + $table->addColumn('group_id', 'string', [ + 'notnull' => false, + 'length' => 64, + ]); + $table->setPrimaryKey(['applicable_id']); + $table->addIndex(['folder_id'], 'groups_folder'); + $table->addIndex(['group_id'], 'groups_folder_value'); + $table->addUniqueIndex(['folder_id', 'group_id'], 'groups_folder_group'); + } + + if ($schema->hasTable('group_folders_applicable')) { + $schema->dropTable('group_folders_applicable'); + } + + return $schema; + } + + public function postSchemaChange(IOutput $output, \Closure $schemaClosure, array $options) { + if (count($this->applicableData)) { + $query = $this->connection->getQueryBuilder(); + $query->insert('group_folders_groups') + ->values([ + 'folder_id' => $query->createParameter('folder'), + 'group_id' => $query->createParameter('group'), + 'permissions' => $query->createParameter('permissions') + ]); + + foreach($this->applicableData as $data) { + $query->setParameter('folder', $data['folder_id']); + $query->setParameter('group', $data['group_id']); + $query->setParameter('permissions', $data['permissions']); + + $query->execute(); + } + } + } +} diff --git a/tests/Folder/FolderManagerTest.php b/tests/Folder/FolderManagerTest.php index cb453c26..8ceb9f7d 100644 --- a/tests/Folder/FolderManagerTest.php +++ b/tests/Folder/FolderManagerTest.php @@ -44,7 +44,7 @@ class FolderManagerTest extends TestCase { $query->delete('group_folders')->execute(); $query = \OC::$server->getDatabaseConnection()->getQueryBuilder(); - $query->delete('group_folders_applicable')->execute(); + $query->delete('group_folders_groups')->execute(); } private function assertHasFolders($folders) { |