Skip to content

Commit

Permalink
Merge pull request #164 from nextcloud/table-rename
Browse files Browse the repository at this point in the history
 rename applicable folder to comply with oracle limitations
  • Loading branch information
icewind1991 authored Aug 6, 2018
2 parents b8ec476 + 76e7b97 commit d4b6f03
Show file tree
Hide file tree
Showing 7 changed files with 179 additions and 107 deletions.
4 changes: 2 additions & 2 deletions appinfo/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
$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');
});
89 changes: 0 additions & 89 deletions appinfo/database.xml

This file was deleted.

18 changes: 9 additions & 9 deletions appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -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>
12 changes: 6 additions & 6 deletions lib/Folder/FolderManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ private function getAllApplicable() {
$query = $this->connection->getQueryBuilder();

$query->select('folder_id', 'group_id', 'permissions')
->from('group_folders_applicable');
->from('group_folders_groups');

$rows = $query->execute()->fetchAll();

Expand All @@ -149,7 +149,7 @@ public function getFoldersForGroup($groupId) {
->from('group_folders', 'f')
->innerJoin(
'f',
'group_folders_applicable',
'group_folders_groups',
'a',
$query->expr()->eq('f.folder_id', 'a.folder_id')
)
Expand Down Expand Up @@ -190,7 +190,7 @@ public function setMountPoint($folderId, $mountPoint) {
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),
Expand All @@ -202,7 +202,7 @@ public function addApplicableGroup($folderId, $groupId) {
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();
Expand All @@ -211,7 +211,7 @@ public function removeApplicableGroup($folderId, $groupId) {
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)));
Expand Down Expand Up @@ -248,7 +248,7 @@ public function renameFolder($folderId, $newMountPoint) {
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();
}
Expand Down
65 changes: 65 additions & 0 deletions lib/Migration/Version102020Date20180806161449.php
Original file line number Diff line number Diff line change
@@ -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;
}
}
96 changes: 96 additions & 0 deletions lib/Migration/Version103000Date20180806161724.php
Original file line number Diff line number Diff line change
@@ -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();
}
}
}
}
2 changes: 1 addition & 1 deletion tests/Folder/FolderManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ private function clean() {
$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) {
Expand Down

0 comments on commit d4b6f03

Please sign in to comment.