Unverified Commit 9a996136 authored by John Molakvoæ's avatar John Molakvoæ Committed by GitHub
Browse files

Merge pull request #844 from nextcloud/fix/access_object

Fix half access objects
parents c645ee6b bb406fdd
......@@ -11,7 +11,7 @@
- **🔒 Data under your control!** Unlike in Google Forms, Typeform, Doodle and others, the survey info and responses are kept private on your instance.
- **🙋 Get involved!** We have lots of stuff planned like more question types, collaboration on forms, [and much more](https://github.com/nextcloud/forms/milestones)!
<author>Affan Hussain</author>
......@@ -240,7 +240,9 @@ class ApiController extends OCSController {
'type' => 'public'
'type' => 'public',
'users' => [],
'groups' => []
* @copyright Copyright (c) 2021 Jonas Rittershofer <jotoeri@users.noreply.github.com>
* @author Jonas Rittershofer <jotoeri@users.noreply.github.com>
* @license GNU AGPL version 3 or any later version
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* GNU Affero General Public License for more details.
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
namespace OCA\Forms\Migration;
use Closure;
use OCP\DB\ISchemaWrapper;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\IDBConnection;
use OCP\Migration\IOutput;
use OCP\Migration\SimpleMigrationStep;
class Version020202Date20210311150843 extends SimpleMigrationStep {
/** @var IDBConnection */
protected $connection;
* @param IDBConnection $connection
public function __construct(IDBConnection $connection) {
$this->connection = $connection;
* Update old Access-Objects to be full objects containing (empty) user- and group-key.
* @param IOutput $output
* @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
* @param array $options
public function preSchemaChange(IOutput $output, Closure $schemaClosure, array $options) {
$qb_fetch = $this->connection->getQueryBuilder();
$qb_update = $this->connection->getQueryBuilder();
$qb_fetch->select('id', 'access_json')
$cursor = $qb_fetch->execute();
->set('access_json', $qb_update->createParameter('access_json'))
->where($qb_update->expr()->eq('id', $qb_update->createParameter('id')));
while ($row = $cursor->fetch()) {
// Decode access to array (param assoc=true)
$access = json_decode($row['access_json'], true);
$update_necessary = false;
// Add empty Arrays, if they do not exist
if (!array_key_exists('users', $access)) {
$access['users'] = [];
$update_necessary = true;
if (!array_key_exists('groups', $access)) {
$access['groups'] = [];
$update_necessary = true;
// If it was necessary, to insert users or groups, update the table
if ($update_necessary) {
$qb_update->setParameter('id', $row['id'], IQueryBuilder::PARAM_INT)
->setParameter('access_json', json_encode($access), IQueryBuilder::PARAM_STR);
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment