summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--apps/twofactor_backupcodes/appinfo/app.php10
-rw-r--r--apps/twofactor_backupcodes/lib/AppInfo/Application.php62
-rw-r--r--apps/twofactor_backupcodes/lib/Db/BackupCodeMapper.php12
-rw-r--r--lib/private/Accounts/AccountManager.php13
-rw-r--r--lib/private/Files/Type/Loader.php15
-rw-r--r--lib/private/Installer.php28
-rw-r--r--lib/private/User/User.php5
-rw-r--r--lib/private/legacy/app.php29
-rw-r--r--settings/ajax/installapp.php52
-rw-r--r--version.php4
10 files changed, 137 insertions, 93 deletions
diff --git a/apps/twofactor_backupcodes/appinfo/app.php b/apps/twofactor_backupcodes/appinfo/app.php
index 0cb10531360..34b4866af2d 100644
--- a/apps/twofactor_backupcodes/appinfo/app.php
+++ b/apps/twofactor_backupcodes/appinfo/app.php
@@ -1,7 +1,8 @@
<?php
-
/**
- * @author Christoph Wurst <christoph@winzerhof-wurst.at>
+ * @copyright Copyright (c) 2017 Joas Schilling <coding@schilljs.com>
+ *
+ * @author Joas Schilling <coding@schilljs.com>
*
* @license GNU AGPL version 3 or any later version
*
@@ -20,6 +21,5 @@
*
*/
-// @codeCoverageIgnoreStart
-OC_App::registerPersonal('twofactor_backupcodes', 'settings/personal');
-// @codeCoverageIgnoreEnd
+$app = new \OCA\TwoFactorBackupCodes\AppInfo\Application();
+$app->register();
diff --git a/apps/twofactor_backupcodes/lib/AppInfo/Application.php b/apps/twofactor_backupcodes/lib/AppInfo/Application.php
new file mode 100644
index 00000000000..ad92c0b1476
--- /dev/null
+++ b/apps/twofactor_backupcodes/lib/AppInfo/Application.php
@@ -0,0 +1,62 @@
+<?php
+/**
+ * @copyright Copyright (c) 2017 Joas Schilling <coding@schilljs.com>
+ *
+ * @author Joas Schilling <coding@schilljs.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
+ * 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
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace OCA\TwoFactorBackupCodes\AppInfo;
+
+use OCA\TwoFactorBackupCodes\Db\BackupCodeMapper;
+use OCP\AppFramework\App;
+use OCP\Util;
+
+class Application extends App {
+ public function __construct () {
+ parent::__construct('twofactor_backupcodes');
+ }
+
+ /**
+ * Register the different app parts
+ */
+ public function register() {
+ $this->registerHooksAndEvents();
+ $this->registerPersonalPage();
+ }
+
+ /**
+ * Register the hooks and events
+ */
+ public function registerHooksAndEvents() {
+ Util::connectHook('OC_User', 'post_deleteUser', $this, 'deleteUser');
+ }
+
+ public function deleteUser($params) {
+ /** @var BackupCodeMapper $mapper */
+ $mapper = $this->getContainer()->query(BackupCodeMapper::class);
+ $mapper->deleteCodesByUserId($params['uid']);
+ }
+
+ /**
+ * Register personal settings for notifications and emails
+ */
+ public function registerPersonalPage() {
+ \OCP\App::registerPersonal($this->getContainer()->getAppName(), 'settings/personal');
+ }
+}
diff --git a/apps/twofactor_backupcodes/lib/Db/BackupCodeMapper.php b/apps/twofactor_backupcodes/lib/Db/BackupCodeMapper.php
index 85cc174fb6a..ff993683c59 100644
--- a/apps/twofactor_backupcodes/lib/Db/BackupCodeMapper.php
+++ b/apps/twofactor_backupcodes/lib/Db/BackupCodeMapper.php
@@ -52,12 +52,22 @@ class BackupCodeMapper extends Mapper {
}, $rows);
}
+ /**
+ * @param IUser $user
+ */
public function deleteCodes(IUser $user) {
+ $this->deleteCodesByUserId($user->getUID());
+ }
+
+ /**
+ * @param string $uid
+ */
+ public function deleteCodesByUserId($uid) {
/* @var IQueryBuilder $qb */
$qb = $this->db->getQueryBuilder();
$qb->delete('twofactor_backup_codes')
- ->where($qb->expr()->eq('user_id', $qb->createNamedParameter($user->getUID())));
+ ->where($qb->expr()->eq('user_id', $qb->createNamedParameter($uid)));
$qb->execute();
}
diff --git a/lib/private/Accounts/AccountManager.php b/lib/private/Accounts/AccountManager.php
index 41fdad148aa..7db686c33a1 100644
--- a/lib/private/Accounts/AccountManager.php
+++ b/lib/private/Accounts/AccountManager.php
@@ -114,6 +114,19 @@ class AccountManager {
}
/**
+ * delete user from accounts table
+ *
+ * @param IUser $user
+ */
+ public function deleteUser(IUser $user) {
+ $uid = $user->getUID();
+ $query = $this->connection->getQueryBuilder();
+ $query->delete($this->table)
+ ->where($query->expr()->eq('uid', $query->createNamedParameter($uid)))
+ ->execute();
+ }
+
+ /**
* get stored data from a given user
*
* @param IUser $user
diff --git a/lib/private/Files/Type/Loader.php b/lib/private/Files/Type/Loader.php
index 4dd798e7b07..1ae783e8f83 100644
--- a/lib/private/Files/Type/Loader.php
+++ b/lib/private/Files/Type/Loader.php
@@ -154,18 +154,23 @@ class Loader implements IMimeTypeLoader {
* Update filecache mimetype based on file extension
*
* @param string $ext file extension
- * @param int $mimetypeId
+ * @param int $mimeTypeId
* @return int number of changed rows
*/
- public function updateFilecache($ext, $mimetypeId) {
+ public function updateFilecache($ext, $mimeTypeId) {
+ $folderMimeTypeId = $this->getId('httpd/unix-directory');
$update = $this->dbConnection->getQueryBuilder();
$update->update('filecache')
- ->set('mimetype', $update->createNamedParameter($mimetypeId))
+ ->set('mimetype', $update->createNamedParameter($mimeTypeId))
->where($update->expr()->neq(
- 'mimetype', $update->createNamedParameter($mimetypeId)
+ 'mimetype', $update->createNamedParameter($mimeTypeId)
+ ))
+ ->andWhere($update->expr()->neq(
+ 'mimetype', $update->createNamedParameter($folderMimeTypeId)
))
->andWhere($update->expr()->like(
- $update->createFunction('LOWER(`name`)'), $update->createNamedParameter($ext)
+ $update->createFunction('LOWER(' . $update->getColumnName('name') . ')'),
+ $update->createNamedParameter('%' . $this->dbConnection->escapeLikeParameter('.' . $ext))
));
return $update->execute();
}
diff --git a/lib/private/Installer.php b/lib/private/Installer.php
index 8702f264e54..35f51b19b07 100644
--- a/lib/private/Installer.php
+++ b/lib/private/Installer.php
@@ -98,7 +98,7 @@ class Installer {
*
* @param string $appId App to install
* @throws \Exception
- * @return integer
+ * @return string app ID
*/
public function installApp($appId) {
$app = \OC_App::findAppInDirectories($appId);
@@ -109,6 +109,29 @@ class Installer {
$basedir = $app['path'].'/'.$appId;
$info = OC_App::getAppInfo($basedir.'/appinfo/info.xml', true);
+ $l = \OC::$server->getL10N('core');
+
+ if(!is_array($info)) {
+ throw new \Exception(
+ $l->t('App "%s" cannot be installed because appinfo file cannot be read.',
+ [$info['name']]
+ )
+ );
+ }
+
+ $version = \OCP\Util::getVersion();
+ if (!\OC_App::isAppCompatible($version, $info)) {
+ throw new \Exception(
+ // TODO $l
+ $l->t('App "%s" cannot be installed because it is not compatible with this version of the server.',
+ [$info['name']]
+ )
+ );
+ }
+
+ // check for required dependencies
+ \OC_App::checkAppDependencies($this->config, $l, $info);
+
//install the database
if(is_file($basedir.'/appinfo/database.xml')) {
if (\OC::$server->getAppConfig()->getValue($info['id'], 'installed_version') === null) {
@@ -120,6 +143,9 @@ class Installer {
\OC_App::registerAutoloading($appId, $basedir);
\OC_App::setupBackgroundJobs($info['background-jobs']);
+ if(isset($info['settings']) && is_array($info['settings'])) {
+ \OC::$server->getSettingsManager()->setupSettings($info['settings']);
+ }
//run appinfo/install.php
if((!isset($data['noinstall']) or $data['noinstall']==false)) {
diff --git a/lib/private/User/User.php b/lib/private/User/User.php
index f55807bc769..5e5d3f0d772 100644
--- a/lib/private/User/User.php
+++ b/lib/private/User/User.php
@@ -30,6 +30,7 @@
namespace OC\User;
+use OC\Accounts\AccountManager;
use OC\Files\Cache\Storage;
use OC\Hooks\Emitter;
use OC_Helper;
@@ -235,6 +236,10 @@ class User implements IUser {
$notification->setUser($this->uid);
\OC::$server->getNotificationManager()->markProcessed($notification);
+ /** @var AccountManager $accountManager */
+ $accountManager = \OC::$server->query(AccountManager::class);
+ $accountManager->deleteUser($this);
+
if ($this->emitter) {
$this->emitter->emit('\OC\User', 'postDelete', array($this));
}
diff --git a/lib/private/legacy/app.php b/lib/private/legacy/app.php
index 111da7d0d40..2e9e97d5bd7 100644
--- a/lib/private/legacy/app.php
+++ b/lib/private/legacy/app.php
@@ -357,8 +357,6 @@ class OC_App {
public function enable($appId,
$groups = null) {
self::$enabledAppsCache = []; // flush
- $l = \OC::$server->getL10N('core');
- $config = \OC::$server->getConfig();
// Check if app is already downloaded
$installer = new Installer(
@@ -374,23 +372,7 @@ class OC_App {
$installer->downloadApp($appId);
}
- if (!Installer::isInstalled($appId)) {
- $appId = self::installApp(
- $appId,
- $config,
- $l
- );
- $appPath = self::getAppPath($appId);
- self::registerAutoloading($appId, $appPath);
- $installer->installApp($appId);
- } else {
- // check for required dependencies
- $info = self::getAppInfo($appId);
- self::checkAppDependencies($config, $l, $info);
- $appPath = self::getAppPath($appId);
- self::registerAutoloading($appId, $appPath);
- $installer->installApp($appId);
- }
+ $installer->installApp($appId);
$appManager = \OC::$server->getAppManager();
if (!is_null($groups)) {
@@ -406,13 +388,6 @@ class OC_App {
} else {
$appManager->enableApp($appId);
}
-
- $info = self::getAppInfo($appId);
- if(isset($info['settings']) && is_array($info['settings'])) {
- $appPath = self::getAppPath($appId);
- self::registerAutoloading($appId, $appPath);
- \OC::$server->getSettingsManager()->setupSettings($info['settings']);
- }
}
/**
@@ -1258,7 +1233,7 @@ class OC_App {
* @param array $info
* @throws \Exception
*/
- protected static function checkAppDependencies($config, $l, $info) {
+ public static function checkAppDependencies($config, $l, $info) {
$dependencyAnalyzer = new DependencyAnalyzer(new Platform($config), $l);
$missing = $dependencyAnalyzer->analyze($info);
if (!empty($missing)) {
diff --git a/settings/ajax/installapp.php b/settings/ajax/installapp.php
deleted file mode 100644
index 17e5eadf50e..00000000000
--- a/settings/ajax/installapp.php
+++ /dev/null
@@ -1,52 +0,0 @@
-<?php
-/**
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- *
- * @author Georg Ehrke <georg@owncloud.com>
- * @author Lukas Reschke <lukas@statuscode.ch>
- * @author Robin Appelman <robin@icewind.nl>
- *
- * @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/>
- *
- */
-OCP\JSON::checkAdminUser();
-OCP\JSON::callCheck();
-
-$lastConfirm = (int) \OC::$server->getSession()->get('last-password-confirm');
-if ($lastConfirm < (time() - 30 * 60 + 15)) { // allow 15 seconds delay
- $l = \OC::$server->getL10N('core');
- OC_JSON::error(array( 'data' => array( 'message' => $l->t('Password confirmation is required'))));
- exit();
-}
-
-if (!array_key_exists('appid', $_POST)) {
- OC_JSON::error();
- exit;
-}
-
-$app = new OC_App();
-$appId = (string)$_POST['appid'];
-$appId = OC_App::cleanAppId($appId);
-$result = $app->installApp(
- $appId,
- \OC::$server->getConfig(),
- \OC::$server->getL10N('core')
-);
-if($result !== false) {
- OC_JSON::success(array('data' => array('appid' => $appId)));
-} else {
- $l = \OC::$server->getL10N('settings');
- OC_JSON::error(array("data" => array( "message" => $l->t("Couldn't remove app.") )));
-}
diff --git a/version.php b/version.php
index 84b84e1016e..b70a985a9c3 100644
--- a/version.php
+++ b/version.php
@@ -26,10 +26,10 @@
// between betas, final and RCs. This is _not_ the public version number. Reset minor/patchlevel
// when updating major/minor version number.
-$OC_Version = array(12, 0, 0, 19);
+$OC_Version = array(12, 0, 0, 20);
// The human readable string
-$OC_VersionString = '12.0 beta 2';
+$OC_VersionString = '12.0 beta 3';
$OC_VersionCanBeUpgradedFrom = [
'nextcloud' => [