2016-05-30 12:56:19 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* @copyright Copyright (c) 2016, ownCloud, Inc.
|
2016-07-21 15:07:57 +00:00
|
|
|
*
|
|
|
|
* @author Roeland Jago Douma <roeland@famdouma.nl>
|
|
|
|
*
|
2016-05-30 12:56:19 +00:00
|
|
|
* @license AGPL-3.0
|
|
|
|
*
|
|
|
|
* This code is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License, version 3,
|
|
|
|
* as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License, version 3,
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
namespace OC\Repair;
|
|
|
|
|
2016-06-03 12:43:31 +00:00
|
|
|
use Doctrine\DBAL\Platforms\OraclePlatform;
|
2016-05-30 12:56:19 +00:00
|
|
|
use OCP\IDBConnection;
|
|
|
|
use OCP\Migration\IOutput;
|
|
|
|
use OCP\Migration\IRepairStep;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class AvatarPermissions
|
|
|
|
*
|
|
|
|
* @package OC\Repair
|
|
|
|
*/
|
|
|
|
class AvatarPermissions implements IRepairStep {
|
|
|
|
/** @var IDBConnection */
|
|
|
|
private $connection;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* AvatarPermissions constructor.
|
|
|
|
*
|
|
|
|
* @param IDBConnection $connection
|
|
|
|
*/
|
|
|
|
public function __construct(IDBConnection $connection) {
|
|
|
|
$this->connection = $connection;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getName() {
|
|
|
|
return 'Fix permissions so avatars can be stored again';
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param IOutput $output
|
|
|
|
*/
|
|
|
|
public function run(IOutput $output) {
|
|
|
|
$output->startProgress(2);
|
|
|
|
$this->fixUserRootPermissions();
|
|
|
|
$output->advance();
|
|
|
|
$this->fixAvatarPermissions();
|
|
|
|
$output->finishProgress();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Make sure all user roots have permissions 23 (all but share)
|
|
|
|
*/
|
|
|
|
protected function fixUserRootPermissions() {
|
|
|
|
$qb = $this->connection->getQueryBuilder();
|
|
|
|
$qb2 = $this->connection->getQueryBuilder();
|
|
|
|
|
|
|
|
$qb->select('numeric_id')
|
|
|
|
->from('storages')
|
|
|
|
->where($qb->expr()->like('id', $qb2->createParameter('like')));
|
|
|
|
|
2016-06-03 12:43:31 +00:00
|
|
|
if ($this->connection->getDatabasePlatform() instanceof OraclePlatform) {
|
|
|
|
// '' is null on oracle
|
|
|
|
$path = $qb2->expr()->isNull('path');
|
|
|
|
} else {
|
|
|
|
$path = $qb2->expr()->eq('path', $qb2->createNamedParameter(''));
|
|
|
|
}
|
|
|
|
|
2016-05-30 12:56:19 +00:00
|
|
|
$qb2->update('filecache')
|
|
|
|
->set('permissions', $qb2->createNamedParameter(23))
|
2016-06-03 12:43:31 +00:00
|
|
|
->where($path)
|
2016-05-30 12:56:19 +00:00
|
|
|
->andWhere($qb2->expr()->in('storage', $qb2->createFunction($qb->getSQL())))
|
|
|
|
->andWhere($qb2->expr()->neq('permissions', $qb2->createNamedParameter(23)))
|
|
|
|
->setParameter('like', 'home::%');
|
|
|
|
|
|
|
|
|
|
|
|
$qb2->execute();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Make sure all avatar files in the user roots have permission 27
|
|
|
|
*/
|
|
|
|
protected function fixAvatarPermissions() {
|
|
|
|
$qb = $this->connection->getQueryBuilder();
|
|
|
|
$qb2 = $this->connection->getQueryBuilder();
|
|
|
|
|
|
|
|
$qb->select('numeric_id')
|
|
|
|
->from('storages')
|
|
|
|
->where($qb->expr()->like('id', $qb2->createParameter('like')));
|
|
|
|
|
|
|
|
$qb2->update('filecache')
|
|
|
|
->set('permissions', $qb2->createNamedParameter(27))
|
|
|
|
->where($qb2->expr()->like('path', $qb2->createNamedParameter('avatar.%')))
|
|
|
|
->andWhere($qb2->expr()->in('storage', $qb2->createFunction($qb->getSQL())))
|
|
|
|
->andWhere($qb2->expr()->neq('permissions', $qb2->createNamedParameter(27)))
|
|
|
|
->setParameter('like', 'home::%');
|
|
|
|
|
|
|
|
$qb2->execute();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|