function cleanDB()
 {
     $query1 = OC_DB::prepare('DELETE FROM *PREFIX*bookmarks');
     $query1->execute();
     $query2 = OC_DB::prepare('DELETE FROM *PREFIX*bookmarks_tags');
     $query2->execute();
 }
 /**
  * Send an email to {$limit} users
  *
  * @param int $limit Number of users we want to send an email to
  * @return int Number of users we sent an email to
  */
 protected function runStep($limit)
 {
     // Get all users which should receive an email
     $affectedUsers = $this->mqHandler->getAffectedUsers($limit);
     if (empty($affectedUsers)) {
         // No users found to notify, mission abort
         return 0;
     }
     $preferences = new \OC\Preferences(\OC_DB::getConnection());
     $userLanguages = $preferences->getValueForUsers('core', 'lang', $affectedUsers);
     $userEmails = $preferences->getValueForUsers('settings', 'email', $affectedUsers);
     // Get all items for these users
     // We don't use time() but "time() - 1" here, so we don't run into
     // runtime issues and delete emails later, which were created in the
     // same second, but were not collected for the emails.
     $sendTime = time() - 1;
     $mailData = $this->mqHandler->getItemsForUsers($affectedUsers, $sendTime);
     // Send Email
     $default_lang = \OC_Config::getValue('default_language', 'en');
     foreach ($mailData as $user => $data) {
         if (!isset($userEmails[$user])) {
             // The user did not setup an email address
             // So we will not send an email :(
             continue;
         }
         $language = isset($userLanguages[$user]) ? $userLanguages[$user] : $default_lang;
         $this->mqHandler->sendEmailToUser($user, $userEmails[$user], $language, $data);
     }
     // Delete all entries we dealt with
     $this->mqHandler->deleteSentItems($affectedUsers, $sendTime);
     return sizeof($affectedUsers);
 }
Example #3
0
 /**
  * get the size of a folder and set it in the cache
  *
  * @param string $path
  * @param array $entry (optional) meta data of the folder
  * @return int
  */
 public function calculateFolderSize($path, $entry = null)
 {
     if ($path !== '/' and $path !== '' and $path !== 'files' and $path !== 'files_trashbin' and $path !== 'files_versions') {
         return parent::calculateFolderSize($path, $entry);
     } elseif ($path === '' or $path === '/') {
         // since the size of / isn't used (the size of /files is used instead) there is no use in calculating it
         return 0;
     }
     $totalSize = 0;
     if (is_null($entry)) {
         $entry = $this->get($path);
     }
     if ($entry && $entry['mimetype'] === 'httpd/unix-directory') {
         $id = $entry['fileid'];
         $sql = 'SELECT SUM(`size`) AS f1, ' . 'SUM(`unencrypted_size`) AS f2 FROM `*PREFIX*filecache` ' . 'WHERE `parent` = ? AND `storage` = ? AND `size` >= 0';
         $result = \OC_DB::executeAudited($sql, array($id, $this->getNumericStorageId()));
         if ($row = $result->fetchRow()) {
             list($sum, $unencryptedSum) = array_values($row);
             $totalSize = 0 + $sum;
             $unencryptedSize = 0 + $unencryptedSum;
             $entry['size'] += 0;
             $entry['unencrypted_size'] += 0;
             if ($entry['size'] !== $totalSize) {
                 $this->update($id, array('size' => $totalSize));
             }
             if ($entry['unencrypted_size'] !== $unencryptedSize) {
                 $this->update($id, array('unencrypted_size' => $unencryptedSize));
             }
         }
     }
     return $totalSize;
 }
Example #4
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $this->validateInput($input, $output);
     $this->readPassword($input, $output);
     $fromDB = \OC_DB::getConnection();
     $toDB = $this->getToDBConnection($input, $output);
     if ($input->getOption('clear-schema')) {
         $this->clearSchema($toDB, $input, $output);
     }
     $this->createSchema($toDB, $input, $output);
     $toTables = $this->getTables($toDB);
     $fromTables = $this->getTables($fromDB);
     // warn/fail if there are more tables in 'from' database
     $extraFromTables = array_diff($fromTables, $toTables);
     if (!empty($extraFromTables)) {
         $output->writeln('<comment>The following tables will not be converted:</comment>');
         $output->writeln($extraFromTables);
         if (!$input->getOption('all-apps')) {
             $output->writeln('<comment>Please note that tables belonging to available but currently not installed apps</comment>');
             $output->writeln('<comment>can be included by specifying the --all-apps option.</comment>');
         }
         /** @var $dialog \Symfony\Component\Console\Helper\DialogHelper */
         $dialog = $this->getHelperSet()->get('dialog');
         if (!$dialog->askConfirmation($output, '<question>Continue with the conversion (y/n)? [n] </question>', false)) {
             return;
         }
     }
     $intersectingTables = array_intersect($toTables, $fromTables);
     $this->convertDB($fromDB, $toDB, $intersectingTables, $input, $output);
 }
Example #5
0
/**
 * lookup file path and owner by fetching it from the fscache
 * needed becaus OC_FileCache::getPath($id, $user) already requires the user
 * @param int $id
 * @return array
 */
function getPathAndUser($id)
{
    $query = \OC_DB::prepare('SELECT `user`, `path` FROM `*PREFIX*fscache` WHERE `id` = ?');
    $result = $query->execute(array($id));
    $row = $result->fetchRow();
    return $row;
}
Example #6
0
 /**
  * test if the mount point moves up if the parent folder no longer exists
  */
 function testShareMountLoseParentFolder()
 {
     // share to user
     $fileinfo = $this->view->getFileInfo($this->folder);
     $result = \OCP\Share::shareItem('folder', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER2, 31);
     $statement = "UPDATE `*PREFIX*share` SET `file_target` = ? where `share_with` = ?";
     $query = \OC_DB::prepare($statement);
     $arguments = array('/foo/bar' . $this->folder, self::TEST_FILES_SHARING_API_USER2);
     $query->execute($arguments);
     $query = \OC_DB::prepare('SELECT * FROM `*PREFIX*share`');
     $result = $query->execute();
     $shares = $result->fetchAll();
     $this->assertSame(1, count($shares));
     $share = reset($shares);
     $this->assertSame('/foo/bar' . $this->folder, $share['file_target']);
     self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
     // share should have moved up
     $query = \OC_DB::prepare('SELECT * FROM `*PREFIX*share`');
     $result = $query->execute();
     $shares = $result->fetchAll();
     $this->assertSame(1, count($shares));
     $share = reset($shares);
     $this->assertSame($this->folder, $share['file_target']);
     //cleanup
     self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
     \OCP\Share::unshare('folder', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER2);
     $this->view->unlink($this->folder);
 }
Example #7
0
 public static function scan($id, $path, $storage)
 {
     $file = $storage->getLocalFile($path);
     $result = OC_Files_Antivirus::clamav_scan($file);
     switch ($result) {
         case CLAMAV_SCANRESULT_UNCHECKED:
             \OCP\Util::writeLog('files_antivirus', 'File "' . $path . '" from user "' . $user . '": is not checked', \OCP\Util::ERROR);
             break;
         case CLAMAV_SCANRESULT_INFECTED:
             $infected_action = \OCP\Config::getAppValue('files_antivirus', 'infected_action', 'only_log');
             if ($infected_action == 'delete') {
                 \OCP\Util::writeLog('files_antivirus', 'File "' . $path . '" from user "' . $user . '": is infected, file deleted', \OCP\Util::ERROR);
                 unlink($file);
             } else {
                 \OCP\Util::writeLog('files_antivirus', 'File "' . $path . '" from user "' . $user . '": is infected', \OCP\Util::ERROR);
             }
             break;
         case CLAMAV_SCANRESULT_CLEAN:
             $stmt = OCP\DB::prepare('INSERT INTO `*PREFIX*files_antivirus` (`fileid`, `check_time`) VALUES (?, ?)');
             try {
                 $result = $stmt->execute(array($id, time()));
                 if (\OC_DB::isError($result)) {
                     \OC_Log::write('files_antivirus', __METHOD__ . ', DB error: ' . \OC_DB::getErrorMessage($result), \OCP\Util::ERROR);
                     return;
                 }
             } catch (\Exception $e) {
                 \OCP\Util::writeLog('files_antivirus', __METHOD__ . ', exception: ' . $e->getMessage(), \OCP\Util::ERROR);
             }
             break;
     }
 }
Example #8
0
 public function getChildren($itemSource)
 {
     $children = array();
     $parents = array($itemSource);
     $query = \OC_DB::prepare('SELECT `id` FROM `*PREFIX*mimetypes` WHERE `mimetype` = ?');
     $result = $query->execute(array('httpd/unix-directory'));
     if ($row = $result->fetchRow()) {
         $mimetype = $row['id'];
     } else {
         $mimetype = -1;
     }
     while (!empty($parents)) {
         $parents = "'" . implode("','", $parents) . "'";
         $query = OC_DB::prepare('SELECT `fileid`, `name`, `mimetype` FROM `*PREFIX*filecache`' . ' WHERE `parent` IN (' . $parents . ')');
         $result = $query->execute();
         $parents = array();
         while ($file = $result->fetchRow()) {
             $children[] = array('source' => $file['fileid'], 'file_path' => $file['name']);
             // If a child folder is found look inside it
             if ($file['mimetype'] == $mimetype) {
                 $parents[] = $file['fileid'];
             }
         }
     }
     return $children;
 }
Example #9
0
 /**
  * get the size of a folder and set it in the cache
  *
  * @param string $path
  * @return int
  */
 public function calculateFolderSize($path)
 {
     if ($path !== '/' and $path !== '' and $path !== 'files') {
         return parent::calculateFolderSize($path);
     }
     $totalSize = 0;
     $entry = $this->get($path);
     if ($entry && $entry['mimetype'] === 'httpd/unix-directory') {
         $id = $entry['fileid'];
         $sql = 'SELECT SUM(`size`) AS f1, ' . 'SUM(`unencrypted_size`) AS f2 FROM `*PREFIX*filecache` ' . 'WHERE `parent` = ? AND `storage` = ? AND `size` >= 0';
         $result = \OC_DB::executeAudited($sql, array($id, $this->getNumericStorageId()));
         if ($row = $result->fetchRow()) {
             list($sum, $unencryptedSum) = array_values($row);
             $totalSize = (int) $sum;
             $unencryptedSize = (int) $unencryptedSum;
             if ($entry['size'] !== $totalSize) {
                 $this->update($id, array('size' => $totalSize));
             }
             if ($entry['unencrypted_size'] !== $unencryptedSize) {
                 $this->update($id, array('unencrypted_size' => $unencryptedSize));
             }
         }
     }
     return $totalSize;
 }
 /**
  * Create a storage entry
  *
  * @param string $storageId
  */
 private function createStorage($storageId)
 {
     $sql = 'INSERT INTO `*PREFIX*storages` (`id`)' . ' VALUES (?)';
     $storageId = \OC\Files\Cache\Storage::adjustStorageId($storageId);
     $numRows = $this->connection->executeUpdate($sql, array($storageId));
     $this->assertEquals(1, $numRows);
     return \OC_DB::insertid('*PREFIX*storages');
 }
Example #11
0
	/**
	 * Returns the id of a given mime type or null
	 * if it does not exist.
	 */
	private function getMimeTypeIdFromDB($mimeType) {
		$sql = 'SELECT `id` FROM `*PREFIX*mimetypes` WHERE `mimetype` = ?';
		$results = \OC_DB::executeAudited($sql, [$mimeType]);
		$result = $results->fetchOne();
		if ($result) {
			return $result['id'];
		}
		return null;
	}
Example #12
0
 public function setUp()
 {
     $this->connection = \OC_DB::getConnection();
     if ($this->connection->getDriver() instanceof \Doctrine\DBAL\Driver\OCI8\Driver) {
         $this->markTestSkipped('DB migration tests arent supported on OCI');
     }
     $this->manager = new \OC\DB\MDB2SchemaManager($this->connection);
     $this->tableName = 'test_' . uniqid();
 }
Example #13
0
 public function setUp()
 {
     $this->connection = \OC_DB::getConnection();
     if (!$this->connection->getDatabasePlatform() instanceof \Doctrine\DBAL\Platforms\MySqlPlatform) {
         $this->markTestSkipped("Test only relevant on MySql");
     }
     $dbPrefix = \OC::$server->getConfig()->getSystemValue("dbtableprefix");
     $this->tableName = uniqid($dbPrefix . "_enum_bit_test");
     $this->connection->exec("CREATE TABLE {$this->tableName}(b BIT,  e ENUM('1','2','3','4'))");
 }
 /**
  * find the user that can be authenticated with an openid identity
  */
 public static function findUserForIdentity($identity)
 {
     $query = OC_DB::prepare('SELECT userid FROM *PREFIX*preferences WHERE appid=? AND configkey=? AND configvalue=?');
     $result = $query->execute(array('user_openid', 'identity', $identity))->fetchAll();
     if (count($result) > 0) {
         return $result[0]['userid'];
     } else {
         return false;
     }
 }
Example #15
0
 public function setUp()
 {
     $this->connection = \OC_DB::getConnection();
     if (!$this->connection->getDatabasePlatform() instanceof \Doctrine\DBAL\Platforms\SqlitePlatform) {
         $this->markTestSkipped("Test only relevant on Sqlite");
     }
     $dbPrefix = \OC::$server->getConfig()->getSystemValue("dbtableprefix");
     $this->tableName = uniqid($dbPrefix . "_enum_bit_test");
     $this->connection->exec("CREATE TABLE {$this->tableName}(t0 tinyint unsigned, t1 tinyint)");
 }
Example #16
0
 /**
  * Retrieves the contents of a trash bin directory.
  * @param string $dir path to the directory inside the trashbin
  * or empty to retrieve the root of the trashbin
  * @return array of files
  */
 public static function getTrashFiles($dir)
 {
     $result = array();
     $user = \OCP\User::getUser();
     if ($dir && $dir !== '/') {
         $view = new \OC_Filesystemview('/' . $user . '/files_trashbin/files');
         $dirContent = $view->opendir($dir);
         if ($dirContent === false) {
             return null;
         }
         if (is_resource($dirContent)) {
             while (($entryName = readdir($dirContent)) !== false) {
                 if (!\OC\Files\Filesystem::isIgnoredDir($entryName)) {
                     $pos = strpos($dir . '/', '/', 1);
                     $tmp = substr($dir, 0, $pos);
                     $pos = strrpos($tmp, '.d');
                     $timestamp = substr($tmp, $pos + 2);
                     $result[] = array('id' => $entryName, 'timestamp' => $timestamp, 'mime' => $view->getMimeType($dir . '/' . $entryName), 'type' => $view->is_dir($dir . '/' . $entryName) ? 'dir' : 'file', 'location' => $dir);
                 }
             }
             closedir($dirContent);
         }
     } else {
         $query = \OC_DB::prepare('SELECT `id`,`location`,`timestamp`,`type`,`mime` FROM `*PREFIX*files_trash` WHERE `user` = ?');
         $result = $query->execute(array($user))->fetchAll();
     }
     $files = array();
     $id = 0;
     foreach ($result as $r) {
         $i = array();
         $i['id'] = $id++;
         $i['name'] = $r['id'];
         $i['date'] = \OCP\Util::formatDate($r['timestamp']);
         $i['timestamp'] = $r['timestamp'];
         $i['etag'] = $i['timestamp'];
         // dummy etag
         $i['mimetype'] = $r['mime'];
         $i['type'] = $r['type'];
         if ($i['type'] === 'file') {
             $fileinfo = pathinfo($r['id']);
             $i['basename'] = $fileinfo['filename'];
             $i['extension'] = isset($fileinfo['extension']) ? '.' . $fileinfo['extension'] : '';
         }
         $i['directory'] = $r['location'];
         if ($i['directory'] === '/') {
             $i['directory'] = '';
         }
         $i['permissions'] = \OCP\PERMISSION_READ;
         $i['isPreviewAvailable'] = \OC::$server->getPreviewManager()->isMimeSupported($r['mime']);
         $i['icon'] = \OCA\Files\Helper::determineIcon($i);
         $files[] = $i;
     }
     usort($files, array('\\OCA\\Files\\Helper', 'fileCmp'));
     return $files;
 }
Example #17
0
 public function setupDatabase($username)
 {
     $datadir = \OC_Config::getValue('datadirectory');
     //delete the old sqlite database first, might cause infinte loops otherwise
     if (file_exists("{$datadir}/owncloud.db")) {
         unlink("{$datadir}/owncloud.db");
     }
     //in case of sqlite, we can always fill the database
     error_log("creating sqlite db");
     \OC_DB::createDbFromStructure($this->dbDefinitionFile);
 }
Example #18
0
 /**
  * Returns the repair steps to be run before an
  * upgrade.
  *
  * @return array of RepairStep instances
  */
 public static function getBeforeUpgradeRepairSteps()
 {
     $steps = array(new \OC\Repair\InnoDB(), new \OC\Repair\Collation(\OC::$server->getConfig(), \OC_DB::getConnection()), new \OC\Repair\SearchLuceneTables(), new \OC\Repair\RepairConfig());
     //There is no need to delete all previews on every single update
     //only 7.0.0 thru 7.0.2 generated broken previews
     $currentVersion = \OC_Config::getValue('version');
     if (version_compare($currentVersion, '7.0.0.0', '>=') && version_compare($currentVersion, '7.0.3.4', '<=')) {
         $steps[] = new \OC\Repair\Preview();
     }
     return $steps;
 }
Example #19
0
 public function setupDatabase($username)
 {
     //check if the database user has admin right
     $connection = @mysql_connect($this->dbhost, $this->dbuser, $this->dbpassword);
     if (!$connection) {
         throw new \OC\DatabaseSetupException($this->trans->t('MySQL/MariaDB username and/or password not valid'), $this->trans->t('You need to enter either an existing account or the administrator.'));
     }
     //user already specified in config
     $oldUser = \OC_Config::getValue('dbuser', false);
     //we don't have a dbuser specified in config
     if ($this->dbuser != $oldUser) {
         //add prefix to the admin username to prevent collisions
         $adminUser = substr('oc_' . $username, 0, 16);
         $i = 1;
         while (true) {
             //this should be enough to check for admin rights in mysql
             $query = "SELECT user FROM mysql.user WHERE user='******'";
             $result = mysql_query($query, $connection);
             //current dbuser has admin rights
             if ($result) {
                 //new dbuser does not exist
                 if (mysql_num_rows($result) === 0) {
                     //use the admin login data for the new database user
                     $this->dbuser = $adminUser;
                     //create a random password so we don't need to store the admin password in the config file
                     $this->dbpassword = \OC_Util::generateRandomBytes(30);
                     $this->createDBUser($connection);
                     break;
                 } else {
                     //repeat with different username
                     $length = strlen((string) $i);
                     $adminUser = substr('oc_' . $username, 0, 16 - $length) . $i;
                     $i++;
                 }
             } else {
                 break;
             }
         }
         \OC_Config::setValue('dbuser', $this->dbuser);
         \OC_Config::setValue('dbpassword', $this->dbpassword);
     }
     //create the database
     $this->createDatabase($connection);
     //fill the database if needed
     $query = 'select count(*) from information_schema.tables' . " where table_schema='" . $this->dbname . "' AND table_name = '" . $this->tableprefix . "users';";
     $result = mysql_query($query, $connection);
     if ($result) {
         $row = mysql_fetch_row($result);
     }
     if (!$result or $row[0] == 0) {
         \OC_DB::createDbFromStructure($this->dbDefinitionFile);
     }
     mysql_close($connection);
 }
Example #20
0
 public function setUp()
 {
     $this->connection = \OC_DB::getConnection();
     if (!$this->connection->getDatabasePlatform() instanceof \Doctrine\DBAL\Platforms\MySqlPlatform) {
         $this->markTestSkipped("Test only relevant on MySql");
     }
     $dbPrefix = \OC::$server->getConfig()->getSystemValue("dbtableprefix");
     $this->tableName = uniqid($dbPrefix . "_innodb_test");
     $this->connection->exec("CREATE TABLE {$this->tableName}(id INT) ENGINE MyISAM");
     $this->repair = new \OC\Repair\InnoDB();
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $file = $input->getArgument('schema-xml');
     $schemaManager = new \OC\DB\MDB2SchemaManager(\OC_DB::getConnection());
     try {
         $result = $schemaManager->updateDbFromStructure($file, true);
         $output->writeln($result);
     } catch (\Exception $e) {
         $output->writeln('Failed to update database structure (' . $e . ')');
     }
 }
Example #22
0
 protected function setUp()
 {
     parent::setUp();
     $this->config = \OC::$server->getConfig();
     $this->connection = \OC_DB::getConnection();
     if ($this->connection->getDatabasePlatform() instanceof OraclePlatform) {
         $this->markTestSkipped('DB migration tests are not supported on OCI');
     }
     $this->manager = new \OC\DB\MDB2SchemaManager($this->connection);
     $this->tableName = strtolower($this->getUniqueID($this->config->getSystemValue('dbtableprefix', 'oc_') . 'test_'));
 }
Example #23
0
 public function setUp()
 {
     $this->connection = \OC_DB::getConnection();
     if ($this->connection->getDatabasePlatform() instanceof OraclePlatform) {
         $this->markTestSkipped('DB migration tests are not supported on OCI');
     }
     if ($this->connection->getDatabasePlatform() instanceof SQLServerPlatform) {
         $this->markTestSkipped('DB migration tests are not supported on MSSQL');
     }
     $this->manager = new \OC\DB\MDB2SchemaManager($this->connection);
     $this->tableName = 'test_' . uniqid();
 }
Example #24
0
 public function setUp()
 {
     $this->connection = \OC_DB::getConnection();
     $this->config = \OC::$server->getConfig();
     if (!$this->connection->getDatabasePlatform() instanceof \Doctrine\DBAL\Platforms\MySqlPlatform) {
         $this->markTestSkipped("Test only relevant on MySql");
     }
     $dbPrefix = $this->config->getSystemValue("dbtableprefix");
     $this->tableName = uniqid($dbPrefix . "_collation_test");
     $this->connection->exec("CREATE TABLE {$this->tableName}(text VARCHAR(16)) COLLATE utf8_unicode_ci");
     $this->repair = new TestCollationRepair($this->config, $this->connection);
 }
Example #25
0
 /**
  * @param array $data
  * @return array
  */
 public function add(array $data)
 {
     $SQL = "INSERT INTO {$this->tableName} (`id`, `type`, `text`, `users`, `start_date`, `end_date`, `duration`, `order`, `progress`, `sortorder`, `parent`, `open`, `buffers`) VALUES ";
     //$this->connect->setSessionTimeZoneToZero();
     //$this->connect->db->executeQuery("SET @@session.time_zone = '00:00'");
     //$query = \OC_DB::prepare('SET @@session.time_zone = "00:00"');
     //$query = \OC_DB::prepare('SET GLOBAL time_zone = "00:00"');
     $query = \OC_DB::prepare("set @@session.time_zone = '+00:00'");
     $query->execute();
     //$this->connect->db->executeQuery("SET time_zone = 'UTC'");
     $rowData = [];
     for ($iRow = 0; $iRow < count($data); $iRow++) {
         $SQL .= (empty($rowData) ? '' : ',') . "( :id_{$iRow}, :type_{$iRow}, :text_{$iRow}, :users_{$iRow}, :start_date_{$iRow}, :end_date_{$iRow}, :duration_{$iRow}, :order_{$iRow}, :progress_{$iRow}, :sortorder_{$iRow}, :parent_{$iRow}, :open_{$iRow}, :buffers_{$iRow} )";
         for ($i = 0; $i < count($this->fields); $i++) {
             $field = $this->fields[$i];
             $value = $data[$iRow][$field];
             if (isset($data[$iRow][$field])) {
                 if ($field == 'id') {
                     $value = (int) $value;
                 } elseif ($field == 'type') {
                     $value = (string) $value;
                 } elseif ($field == 'text') {
                     $value = (string) $value;
                 } elseif ($field == 'users') {
                     $value = (string) $value;
                 } elseif ($field == 'start_date') {
                     $value = empty($value) ? date("Y-m-d H:i:s", time()) : $value;
                 } elseif ($field == 'end_date') {
                     $value = empty($value) ? date("Y-m-d H:i:s", time() + 3600 * 24 * 7) : $value;
                 } elseif ($field == 'duration') {
                     $value = (int) (empty($value) ? 0 : $value);
                 } elseif ($field == 'order') {
                     $value = (int) (empty($value) ? 0 : $value);
                 } elseif ($field == 'progress') {
                     $value = (double) (empty($value) ? 0 : $value);
                 } elseif ($field == 'sortorder') {
                     $value = (int) (empty($value) ? 0 : $value);
                 } elseif ($field == 'parent') {
                     $value = (int) (empty($value) ? 1 : $value);
                 } elseif ($field == 'open') {
                     $value = (int) (empty($value) ? 1 : $value);
                 } elseif ($field == 'buffers') {
                     $value = (string) (empty($value) ? '' : $value);
                 }
                 $rowData[":{$field}_{$iRow}"] = $value;
             } else {
                 $rowData[":{$field}_{$iRow}"] = null;
             }
         }
     }
     return $this->connect->db->prepare($SQL)->execute($rowData);
 }
Example #26
0
 protected function setUp()
 {
     parent::setUp();
     $this->connection = \OC_DB::getConnection();
     if ($this->connection->getDatabasePlatform() instanceof OraclePlatform) {
         $this->markTestSkipped('DB migration tests are not supported on OCI');
     }
     if ($this->connection->getDatabasePlatform() instanceof SQLServerPlatform) {
         $this->markTestSkipped('DB migration tests are not supported on MSSQL');
     }
     $this->manager = new \OC\DB\MDB2SchemaManager($this->connection);
     $this->tableName = strtolower($this->getUniqueID('oc_test_'));
 }
Example #27
0
 /**
  * Fix mime types
  */
 public function run()
 {
     $connection = \OC_DB::getConnection();
     if (!$connection->getDatabasePlatform() instanceof MySqlPlatform) {
         $this->emit('\\OC\\Repair', 'info', array('Not a mysql database -> nothing to no'));
         return;
     }
     $tables = $this->getAllMyIsamTables($connection);
     foreach ($tables as $table) {
         $connection->exec("ALTER TABLE {$table} ENGINE=InnoDB;");
         $this->emit('\\OC\\Repair', 'info', array("Fixed {$table}"));
     }
 }
Example #28
0
 public static function exists($storageId)
 {
     if (strlen($storageId) > 64) {
         $storageId = md5($storageId);
     }
     $sql = 'SELECT `numeric_id` FROM `*PREFIX*storages` WHERE `id` = ?';
     $result = \OC_DB::executeAudited($sql, array($storageId));
     if ($row = $result->fetchRow()) {
         return true;
     } else {
         return false;
     }
 }
Example #29
0
 protected function setUp()
 {
     parent::setUp();
     $this->connection = \OC_DB::getConnection();
     $this->config = \OC::$server->getConfig();
     if (!$this->connection->getDatabasePlatform() instanceof \Doctrine\DBAL\Platforms\SqlitePlatform) {
         $this->markTestSkipped("Test only relevant on Sqlite");
     }
     $dbPrefix = $this->config->getSystemValue('dbtableprefix', 'oc_');
     $this->tableName = $this->getUniqueID($dbPrefix . 'autoinc_test');
     $this->connection->exec('CREATE TABLE ' . $this->tableName . '("someid" INTEGER NOT NULL, "text" VARCHAR(16), PRIMARY KEY("someid"))');
     $this->repair = new \OC\Repair\SqliteAutoincrement($this->connection);
 }
Example #30
0
 /**
  * @brief remove all shares for a given file if the file was deleted
  *
  * @param string $path
  */
 private static function removeShare($path)
 {
     $fileSource = self::$toRemove[$path];
     if (!\OC\Files\Filesystem::file_exists($path)) {
         $query = \OC_DB::prepare('DELETE FROM `*PREFIX*share` WHERE `file_source`=?');
         try {
             \OC_DB::executeAudited($query, array($fileSource));
         } catch (\Exception $e) {
             \OCP\Util::writeLog('files_sharing', "can't remove share: " . $e->getMessage(), \OCP\Util::WARN);
         }
     }
     unset(self::$toRemove[$path]);
 }