Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor OC\Server::getDatabaseConnection #40121

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .htaccess
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,7 @@

AddDefaultCharset utf-8
Options -Indexes
#### DO NOT CHANGE ANYTHING ABOVE THIS LINE ####

ErrorDocument 403 /index.php/error/403
ErrorDocument 404 /index.php/error/404
109 changes: 1 addition & 108 deletions core/js/mimetypelist.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,114 +7,7 @@
* To regenerate this file run ./occ maintenance:mimetype:update-js
*/
OC.MimeTypeList={
aliases: {
"application/coreldraw": "image",
"application/epub+zip": "text",
"application/font-sfnt": "font",
"application/font-woff": "font",
"application/gpx+xml": "location",
"application/illustrator": "image",
"application/javascript": "text/code",
"application/json": "text/code",
"application/msaccess": "file",
"application/msexcel": "x-office/spreadsheet",
"application/msonenote": "x-office/document",
"application/mspowerpoint": "x-office/presentation",
"application/msword": "x-office/document",
"application/octet-stream": "file",
"application/postscript": "image",
"application/rss+xml": "application/xml",
"application/vnd.android.package-archive": "package/x-generic",
"application/vnd.lotus-wordpro": "x-office/document",
"application/vnd.garmin.tcx+xml": "location",
"application/vnd.google-earth.kml+xml": "location",
"application/vnd.google-earth.kmz": "location",
"application/vnd.ms-excel": "x-office/spreadsheet",
"application/vnd.ms-excel.addin.macroEnabled.12": "x-office/spreadsheet",
"application/vnd.ms-excel.sheet.binary.macroEnabled.12": "x-office/spreadsheet",
"application/vnd.ms-excel.sheet.macroEnabled.12": "x-office/spreadsheet",
"application/vnd.ms-excel.template.macroEnabled.12": "x-office/spreadsheet",
"application/vnd.ms-fontobject": "font",
"application/vnd.ms-powerpoint": "x-office/presentation",
"application/vnd.ms-powerpoint.addin.macroEnabled.12": "x-office/presentation",
"application/vnd.ms-powerpoint.presentation.macroEnabled.12": "x-office/presentation",
"application/vnd.ms-powerpoint.slideshow.macroEnabled.12": "x-office/presentation",
"application/vnd.ms-powerpoint.template.macroEnabled.12": "x-office/presentation",
"application/vnd.ms-visio.drawing.macroEnabled.12": "application/vnd.visio",
"application/vnd.ms-visio.drawing": "application/vnd.visio",
"application/vnd.ms-visio.stencil.macroEnabled.12": "application/vnd.visio",
"application/vnd.ms-visio.stencil": "application/vnd.visio",
"application/vnd.ms-visio.template.macroEnabled.12": "application/vnd.visio",
"application/vnd.ms-visio.template": "application/vnd.visio",
"application/vnd.ms-word.document.macroEnabled.12": "x-office/document",
"application/vnd.ms-word.template.macroEnabled.12": "x-office/document",
"application/vnd.oasis.opendocument.presentation": "x-office/presentation",
"application/vnd.oasis.opendocument.presentation-template": "x-office/presentation",
"application/vnd.oasis.opendocument.spreadsheet": "x-office/spreadsheet",
"application/vnd.oasis.opendocument.spreadsheet-template": "x-office/spreadsheet",
"application/vnd.oasis.opendocument.text": "x-office/document",
"application/vnd.oasis.opendocument.text-master": "x-office/document",
"application/vnd.oasis.opendocument.text-template": "x-office/document",
"application/vnd.oasis.opendocument.graphics": "x-office/drawing",
"application/vnd.oasis.opendocument.graphics-template": "x-office/drawing",
"application/vnd.oasis.opendocument.text-web": "x-office/document",
"application/vnd.oasis.opendocument.text-flat-xml": "x-office/document",
"application/vnd.oasis.opendocument.spreadsheet-flat-xml": "x-office/spreadsheet",
"application/vnd.oasis.opendocument.graphics-flat-xml": "x-office/drawing",
"application/vnd.oasis.opendocument.presentation-flat-xml": "x-office/presentation",
"application/vnd.openxmlformats-officedocument.presentationml.presentation": "x-office/presentation",
"application/vnd.openxmlformats-officedocument.presentationml.slideshow": "x-office/presentation",
"application/vnd.openxmlformats-officedocument.presentationml.template": "x-office/presentation",
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet": "x-office/spreadsheet",
"application/vnd.openxmlformats-officedocument.spreadsheetml.template": "x-office/spreadsheet",
"application/vnd.openxmlformats-officedocument.wordprocessingml.document": "x-office/document",
"application/vnd.openxmlformats-officedocument.wordprocessingml.template": "x-office/document",
"application/vnd.visio": "x-office/document",
"application/vnd.wordperfect": "x-office/document",
"application/x-7z-compressed": "package/x-generic",
"application/x-bzip2": "package/x-generic",
"application/x-cbr": "text",
"application/x-compressed": "package/x-generic",
"application/x-dcraw": "image",
"application/x-deb": "package/x-generic",
"application/x-fictionbook+xml": "text",
"application/x-font": "font",
"application/x-gimp": "image",
"application/x-gzip": "package/x-generic",
"application/x-iwork-keynote-sffkey": "x-office/presentation",
"application/x-iwork-numbers-sffnumbers": "x-office/spreadsheet",
"application/x-iwork-pages-sffpages": "x-office/document",
"application/x-mobipocket-ebook": "text",
"application/x-perl": "text/code",
"application/x-photoshop": "image",
"application/x-php": "text/code",
"application/x-rar-compressed": "package/x-generic",
"application/x-tar": "package/x-generic",
"application/x-tex": "text",
"application/xml": "text/html",
"application/yaml": "text/code",
"application/zip": "package/x-generic",
"database": "file",
"httpd/unix-directory": "dir",
"text/css": "text/code",
"text/csv": "x-office/spreadsheet",
"text/html": "text/code",
"text/x-c": "text/code",
"text/x-c++src": "text/code",
"text/x-h": "text/code",
"text/x-java-source": "text/code",
"text/x-ldif": "text/code",
"text/x-python": "text/code",
"text/x-shellscript": "text/code",
"web": "text/code",
"application/internet-shortcut": "link",
"application/km": "mindmap",
"application/x-freemind": "mindmap",
"application/vnd.xmind.workbook": "mindmap",
"image/targa": "image/tga",
"application/vnd.openxmlformats-officedocument.wordprocessingml.document.oform": "x-office/form",
"application/vnd.openxmlformats-officedocument.wordprocessingml.document.docxf": "x-office/form-template"
},
aliases: [],
files: [
"application",
"application-pdf",
Expand Down
3 changes: 2 additions & 1 deletion core/register_command.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*/

use Psr\Log\LoggerInterface;

$application->add(new \Stecman\Component\Symfony\Console\BashCompletion\CompletionCommand());
Expand Down Expand Up @@ -107,7 +108,7 @@
$application->add(\OC::$server->get(OC\Core\Command\Info\Space::class));

$application->add(new OC\Core\Command\Db\ConvertType(\OC::$server->getConfig(), new \OC\DB\ConnectionFactory(\OC::$server->getSystemConfig())));
$application->add(new OC\Core\Command\Db\ConvertMysqlToMB4(\OC::$server->getConfig(), \OC::$server->getDatabaseConnection(), \OC::$server->getURLGenerator(), \OC::$server->get(LoggerInterface::class)));
$application->add(\OCP\Server::get(\OC\Core\Command\Db\ConvertMysqlToMB4::class));
$application->add(new OC\Core\Command\Db\ConvertFilecacheBigInt(\OC::$server->get(\OC\DB\Connection::class)));
$application->add(\OCP\Server::get(\OC\Core\Command\Db\AddMissingColumns::class));
$application->add(\OCP\Server::get(\OC\Core\Command\Db\AddMissingIndices::class));
Expand Down
2 changes: 1 addition & 1 deletion lib/private/AllConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public function __construct(SystemConfig $systemConfig) {
*/
private function fixDIInit() {
if ($this->connection === null) {
$this->connection = \OC::$server->get(IDBConnection::class);
$this->connection = \OCP\Server::get(IDBConnection::class);
}
}

Expand Down
4 changes: 2 additions & 2 deletions lib/private/Files/Cache/Cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public function __construct(IStorage $storage) {

$this->storageCache = new Storage($storage);
$this->mimetypeLoader = \OC::$server->getMimeTypeLoader();
$this->connection = \OC::$server->getDatabaseConnection();
$this->connection = \OCP\Server::get(IDBConnection::class);
$this->eventDispatcher = \OC::$server->get(IEventDispatcher::class);
$this->querySearchHelper = \OCP\Server::get(QuerySearchHelper::class);
}
Expand Down Expand Up @@ -1070,7 +1070,7 @@ public function getPathById($id) {
* @deprecated use getPathById() instead
*/
public static function getById($id) {
$query = \OC::$server->getDatabaseConnection()->getQueryBuilder();
$query = \OCP\Server::get(IDBConnection::class)->getQueryBuilder();
$query->select('path', 'storage')
->from('filecache')
->where($query->expr()->eq('fileid', $query->createNamedParameter($id, IQueryBuilder::PARAM_INT)));
Expand Down
2 changes: 1 addition & 1 deletion lib/private/Files/Cache/Scanner.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public function __construct(\OC\Files\Storage\Storage $storage) {
$this->cache = $storage->getCache();
$this->cacheActive = !\OC::$server->getConfig()->getSystemValueBool('filesystem_cache_readonly', false);
$this->lockingProvider = \OC::$server->getLockingProvider();
$this->connection = \OC::$server->get(IDBConnection::class);
$this->connection = \OCP\Server::get(IDBConnection::class);
}

/**
Expand Down
13 changes: 7 additions & 6 deletions lib/private/Files/Cache/Storage.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\Files\Storage\IStorage;
use OCP\IDBConnection;
use Psr\Log\LoggerInterface;

/**
Expand All @@ -55,7 +56,7 @@ class Storage {
*/
public static function getGlobalCache() {
if (is_null(self::$globalCache)) {
self::$globalCache = new StorageGlobal(\OC::$server->getDatabaseConnection());
self::$globalCache = new StorageGlobal(\OCP\Server::get(IDBConnection::class));
}
return self::$globalCache;
}
Expand All @@ -76,7 +77,7 @@ public function __construct($storage, $isAvailable = true) {
if ($row = self::getStorageById($this->storageId)) {
$this->numericId = (int)$row['numeric_id'];
} else {
$connection = \OC::$server->getDatabaseConnection();
$connection = \OCP\Server::get(IDBConnection::class);
$available = $isAvailable ? 1 : 0;
if ($connection->insertIfNotExist('*PREFIX*storages', ['id' => $this->storageId, 'available' => $available])) {
$this->numericId = $connection->lastInsertId('*PREFIX*storages');
Expand Down Expand Up @@ -174,7 +175,7 @@ public function setAvailability($isAvailable, int $delay = 0) {
\OC::$server->get(LoggerInterface::class)->info('Storage with ' . $this->storageId . ' marked as unavailable', ['app' => 'lib']);
}

$query = \OC::$server->getDatabaseConnection()->getQueryBuilder();
$query = \OCP\Server::get(IDBConnection::class)->getQueryBuilder();
$query->update('storages')
->set('available', $query->createNamedParameter($available))
->set('last_checked', $query->createNamedParameter(time() + $delay))
Expand All @@ -201,13 +202,13 @@ public static function remove($storageId) {
$storageId = self::adjustStorageId($storageId);
$numericId = self::getNumericStorageId($storageId);

$query = \OC::$server->getDatabaseConnection()->getQueryBuilder();
$query = \OCP\Server::get(IDBConnection::class)->getQueryBuilder();
$query->delete('storages')
->where($query->expr()->eq('id', $query->createNamedParameter($storageId)));
$query->execute();

if (!is_null($numericId)) {
$query = \OC::$server->getDatabaseConnection()->getQueryBuilder();
$query = \OCP\Server::get(IDBConnection::class)->getQueryBuilder();
$query->delete('filecache')
->where($query->expr()->eq('storage', $query->createNamedParameter($numericId)));
$query->execute();
Expand All @@ -220,7 +221,7 @@ public static function remove($storageId) {
* @param int $mountId
*/
public static function cleanByMountId(int $mountId) {
$db = \OC::$server->getDatabaseConnection();
$db = \OCP\Server::get(IDBConnection::class);

try {
$db->beginTransaction();
Expand Down
3 changes: 2 additions & 1 deletion lib/private/Files/Cache/Wrapper/CacheJail.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
use OCP\Files\Search\ISearchBinaryOperator;
use OCP\Files\Search\ISearchComparison;
use OCP\Files\Search\ISearchOperator;
use OCP\IDBConnection;

/**
* Jail to a subdirectory of the wrapped cache
Expand All @@ -52,7 +53,7 @@ class CacheJail extends CacheWrapper {
public function __construct($cache, $root) {
parent::__construct($cache);
$this->root = $root;
$this->connection = \OC::$server->getDatabaseConnection();
$this->connection = \OCP\Server::get(IDBConnection::class);
$this->mimetypeLoader = \OC::$server->getMimeTypeLoader();

if ($cache instanceof CacheJail) {
Expand Down
2 changes: 1 addition & 1 deletion lib/private/Files/Cache/Wrapper/CacheWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function __construct($cache) {
$this->querySearchHelper = $cache->querySearchHelper;
} else {
$this->mimetypeLoader = \OC::$server->get(IMimeTypeLoader::class);
$this->connection = \OC::$server->get(IDBConnection::class);
$this->connection = \OCP\Server::get(IDBConnection::class);
$this->querySearchHelper = \OC::$server->get(QuerySearchHelper::class);
}
}
Expand Down
5 changes: 3 additions & 2 deletions lib/private/Files/Storage/Common.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
use OCP\Files\Storage\ILockingStorage;
use OCP\Files\Storage\IStorage;
use OCP\Files\Storage\IWriteStreamStorage;
use OCP\IDBConnection;
use OCP\Lock\ILockingProvider;
use OCP\Lock\LockedException;
use Psr\Log\LoggerInterface;
Expand Down Expand Up @@ -382,7 +383,7 @@ public function getPropagator($storage = null) {
}
if (!isset($storage->propagator)) {
$config = \OC::$server->getSystemConfig();
$storage->propagator = new Propagator($storage, \OC::$server->getDatabaseConnection(), ['appdata_' . $config->getValue('instanceid')]);
$storage->propagator = new Propagator($storage, \OCP\Server::get(IDBConnection::class), ['appdata_' . $config->getValue('instanceid')]);
}
return $storage->propagator;
}
Expand Down Expand Up @@ -536,7 +537,7 @@ public function verifyPath($path, $fileName) {
throw new InvalidDirectoryException();
}

if (!\OC::$server->getDatabaseConnection()->supports4ByteText()) {
if (!\OCP\Server::get(IDBConnection::class)->supports4ByteText()) {
// verify database - e.g. mysql only 3-byte chars
if (preg_match('%(?:
\xF0[\x90-\xBF][\x80-\xBF]{2} # planes 1-3
Expand Down
3 changes: 2 additions & 1 deletion lib/private/Files/Storage/Home.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
namespace OC\Files\Storage;

use OC\Files\Cache\HomePropagator;
use OCP\IDBConnection;
use OCP\IUser;

/**
Expand Down Expand Up @@ -84,7 +85,7 @@ public function getPropagator($storage = null) {
$storage = $this;
}
if (!isset($this->propagator)) {
$this->propagator = new HomePropagator($storage, \OC::$server->getDatabaseConnection());
$this->propagator = new HomePropagator($storage, \OCP\Server::get(IDBConnection::class));
}
return $this->propagator;
}
Expand Down
3 changes: 2 additions & 1 deletion lib/private/Files/Storage/Wrapper/Jail.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
use OCP\Files\Storage\IStorage;
use OCP\Files\Storage\IWriteStreamStorage;
use OCP\Lock\ILockingProvider;
use OCP\IDBConnection;

/**
* Jail to a subdirectory of the wrapped storage
Expand Down Expand Up @@ -513,7 +514,7 @@ public function getPropagator($storage = null) {
if (!$storage) {
$storage = $this;
}
$this->propagator = new JailPropagator($storage, \OC::$server->getDatabaseConnection());
$this->propagator = new JailPropagator($storage, \OCP\Server::get(IDBConnection::class));
return $this->propagator;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/private/Group/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public function __construct(IDBConnection $dbConn = null) {
*/
private function fixDI() {
if ($this->dbConn === null) {
$this->dbConn = \OC::$server->getDatabaseConnection();
$this->dbConn = \OCP\Server::get(IDBConnection::class);
}
}

Expand Down
3 changes: 2 additions & 1 deletion lib/private/Group/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
use OCP\Group\Events\GroupCreatedEvent;
use OCP\GroupInterface;
use OCP\ICacheFactory;
use OCP\IDBConnection;
use OCP\IGroup;
use OCP\IGroupManager;
use OCP\IUser;
Expand Down Expand Up @@ -482,7 +483,7 @@ public function getSubAdmin() {
$this->subAdmin = new \OC\SubAdmin(
$this->userManager,
$this,
\OC::$server->getDatabaseConnection(),
\OCP\Server::get(IDBConnection::class),
$this->dispatcher
);
}
Expand Down
Loading