summaryrefslogtreecommitdiffstats
path: root/apps/files_encryption/lib
diff options
context:
space:
mode:
authorBjörn Schießle <schiessle@owncloud.com>2013-06-12 12:21:11 +0200
committerBjörn Schießle <schiessle@owncloud.com>2013-06-12 12:21:11 +0200
commitc78a90fd54c790a21c9ba4d8dcf86a68ebef0edd (patch)
tree1cc4c2b39fceff037c3d199b7f3ff0e72eeeb2c8 /apps/files_encryption/lib
parent3ec6b19cdf6b1774d359c10f6cd7f74b5f376d18 (diff)
downloadnextcloud-server-c78a90fd54c790a21c9ba4d8dcf86a68ebef0edd.tar.gz
nextcloud-server-c78a90fd54c790a21c9ba4d8dcf86a68ebef0edd.zip
use number of manipulated rows as idicator if it was possible to enter the migration mode
Diffstat (limited to 'apps/files_encryption/lib')
-rw-r--r--apps/files_encryption/lib/util.php88
1 files changed, 20 insertions, 68 deletions
diff --git a/apps/files_encryption/lib/util.php b/apps/files_encryption/lib/util.php
index a5aa121f930..f6da417c6f9 100644
--- a/apps/files_encryption/lib/util.php
+++ b/apps/files_encryption/lib/util.php
@@ -1057,63 +1057,25 @@ class Util {
}
/**
- * @brief Set file migration status for user
- * @param $status
- * @return bool
- */
- private function setMigrationStatus($status) {
-
- $sql = 'UPDATE `*PREFIX*encryption` SET `migration_status` = ? WHERE `uid` = ?';
-
- $args = array(
- $status,
- $this->userId
- );
-
- $query = \OCP\DB::prepare($sql);
-
- if ($query->execute($args)) {
-
- return true;
-
- } else {
- \OCP\Util::writeLog('Encryption library', "Could not set migration status for " . $this->userId, \OCP\Util::ERROR);
- return false;
-
- }
-
- }
-
- /**
* @brief start migration mode to initially encrypt users data
* @return boolean
*/
public function beginMigration() {
-
- $return = false;
- $transaction = \OC_DB::beginTransaction();
-
- if ($transaction === false) {
- \OCP\Util::writeLog('Encryption library', "Your database migration doesn't support transactions", \OCP\Util::WARN);
- }
-
- $migrationStatus = $this->getMigrationStatus();
-
- if ($migrationStatus === self::MIGRATION_OPEN) {
+ $return = false;
- $return = $this->setMigrationStatus(self::MIGRATION_IN_PROGRESS);
+ $sql = 'UPDATE `*PREFIX*encryption` SET `migration_status` = ? WHERE `uid` = ? and `migration_status` = ?';
+ $args = array(self::MIGRATION_IN_PROGRESS, $this->userId, self::MIGRATION_OPEN);
+ $query = \OCP\DB::prepare($sql);
+ $result = $query->execute($args);
+ $manipulatedRows = $result->numRows();
- if ($return === true) {
- \OCP\Util::writeLog('Encryption library', "Enter migration mode for initial encryption for user " . $this->userId, \OCP\Util::INFO);
- } else {
- \OCP\Util::writeLog('Encryption library', "Could not activate migration mode for " . $this->userId . ", encryption aborted", \OCP\Util::ERROR);
- }
+ if ($manipulatedRows === 1) {
+ $return = true;
+ \OCP\Util::writeLog('Encryption library', "Start migration to encryption mode for " . $this->userId, \OCP\Util::INFO);
} else {
- \OCP\Util::writeLog('Encryption library', "Another process already performs the migration for user " . $this->userId, \OCP\Util::WARN);
+ \OCP\Util::writeLog('Encryption library', "Could not activate migration mode for " . $this->userId . ". Probably another process already started the initial encryption", \OCP\Util::WARN);
}
-
- \OC_DB::commit();
return $return;
}
@@ -1126,29 +1088,19 @@ class Util {
$return = false;
- $transaction = \OC_DB::beginTransaction();
-
- if ($transaction === false) {
- \OCP\Util::writeLog('Encryption library', "Your database migration doesn't support transactions", \OCP\Util::WARN);
- }
-
- $migrationStatus = $this->getMigrationStatus();
-
- if ($migrationStatus === self::MIGRATION_IN_PROGRESS) {
-
- $return = $this->setMigrationStatus(self::MIGRATION_COMPLETED);
+ $sql = 'UPDATE `*PREFIX*encryption` SET `migration_status` = ? WHERE `uid` = ? and `migration_status` = ?';
+ $args = array(self::MIGRATION_COMPLETED, $this->userId, self::MIGRATION_IN_PROGRESS);
+ $query = \OCP\DB::prepare($sql);
+ $result = $query->execute($args);
+ $manipulatedRows = $result->numRows();
- if ($return === true) {
- \OCP\Util::writeLog('Encryption library', "Leave migration mode for: " . $this->userId . " successfully.", \OCP\Util::INFO);
- } else {
- \OCP\Util::writeLog('Encryption library', "Could not deactivate migration mode for " . $this->userId, \OCP\Util::ERROR);
- }
+ if ($manipulatedRows === 1) {
+ $result = true;
+ \OCP\Util::writeLog('Encryption library', "Finish migration successfully for " . $this->userId, \OCP\Util::INFO);
} else {
- \OCP\Util::writeLog('Encryption library', "Someone else finished the migration mode to early for user " . $this->userId, \OCP\Util::ERROR);
+ \OCP\Util::writeLog('Encryption library', "Could not deactivate migration mode for " . $this->userId, \OCP\Util::WARN);
}
- \OC_DB::commit();
-
return $return;
}
@@ -1158,7 +1110,7 @@ class Util {
* @note If records are not being returned, check for a hidden space
* at the start of the uid in db
*/
- private function getMigrationStatus() {
+ public function getMigrationStatus() {
$sql = 'SELECT `migration_status` FROM `*PREFIX*encryption` WHERE `uid` = ?';