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

pkp/pkp-lib#9073 laravel update from 9.x to 10.x with database patch up #9105

Closed
wants to merge 15 commits into from
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
3 changes: 2 additions & 1 deletion classes/core/PKPContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,8 @@ public function registerConfiguredProviders()
$this->register(new LaravelEventServiceProvider($this));
$this->register(new EventServiceProvider($this));
$this->register(new LogServiceProvider($this));
$this->register(new \Illuminate\Database\DatabaseServiceProvider($this));
// $this->register(new \Illuminate\Database\DatabaseServiceProvider($this));
$this->register(new \PKP\core\database\PKPDatabaseServiceProvider($this));
$this->register(new \Illuminate\Bus\BusServiceProvider($this));
$this->register(new PKPQueueProvider($this));
$this->register(new MailServiceProvider($this));
Expand Down
41 changes: 41 additions & 0 deletions classes/core/database/PKPDatabaseConnectionFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

namespace PKP\core\database;

use InvalidArgumentException;
use Illuminate\Database\Connection;
use Illuminate\Database\SQLiteConnection;
use Illuminate\Database\SqlServerConnection;
use Illuminate\Database\Connectors\ConnectionFactory;
use PKP\core\database\connections\PKPMySqlConnection;
use PKP\core\database\connections\PKPPostgresConnection;

class PKPDatabaseConnectionFactory extends ConnectionFactory
{
/**
* Create a new connection instance.
*
* @param string $driver
* @param \PDO|\Closure $connection
* @param string $database
* @param string $prefix
* @param array $config
* @return \Illuminate\Database\Connection
*
* @throws \InvalidArgumentException
*/
protected function createConnection($driver, $connection, $database, $prefix = '', array $config = [])
{
if ($resolver = Connection::getResolver($driver)) {
return $resolver($connection, $database, $prefix, $config);
}

return match ($driver) {
'mysql' => new PKPMySqlConnection($connection, $database, $prefix, $config),
'pgsql' => new PKPPostgresConnection($connection, $database, $prefix, $config),
'sqlite' => new SQLiteConnection($connection, $database, $prefix, $config),
'sqlsrv' => new SqlServerConnection($connection, $database, $prefix, $config),
default => throw new InvalidArgumentException("Unsupported driver [{$driver}]."),
};
}
}
46 changes: 46 additions & 0 deletions classes/core/database/PKPDatabaseServiceProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

namespace PKP\core\database;

use Illuminate\Database\DatabaseManager;
use Illuminate\Database\DatabaseServiceProvider;
use PKP\core\database\PKPDatabaseConnectionFactory;
use Illuminate\Database\DatabaseTransactionsManager;


class PKPDatabaseServiceProvider extends DatabaseServiceProvider
{
/**
* Register the primary database bindings.
*
* @return void
*/
protected function registerConnectionServices()
{
// The connection factory is used to create the actual connection instances on
// the database. We will inject the factory into the manager so that it may
// make the connections while they are actually needed and not of before.
$this->app->singleton('db.factory', function ($app) {
return new PKPDatabaseConnectionFactory($app);
});

// The database manager is used to resolve various connections, since multiple
// connections might be managed. It also implements the connection resolver
// interface which may be used by other components requiring connections.
$this->app->singleton('db', function ($app) {
return new DatabaseManager($app, $app['db.factory']);
});

$this->app->bind('db.connection', function ($app) {
return $app['db']->connection();
});

$this->app->bind('db.schema', function ($app) {
return $app['db']->connection()->getSchemaBuilder();
});

$this->app->singleton('db.transactions', function ($app) {
return new DatabaseTransactionsManager;
});
}
}
11 changes: 11 additions & 0 deletions classes/core/database/connections/PKPMySqlConnection.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace PKP\core\database\connections;

use Illuminate\Database\MySqlConnection;
use PKP\core\database\traits\DBConnection;

class PKPMySqlConnection extends MySqlConnection
{
use DBConnection;
}
11 changes: 11 additions & 0 deletions classes/core/database/connections/PKPPostgresConnection.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace PKP\core\database\connections;

use PKP\core\database\traits\DBConnection;
use Illuminate\Database\PostgresConnection;

class PKPPostgresConnection extends PostgresConnection
{
use DBConnection;
}
54 changes: 54 additions & 0 deletions classes/core/database/traits/DBConnection.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php

namespace PKP\core\database\traits;

use Illuminate\Database\Query\Grammars\MySqlGrammar;
use Illuminate\Database\MySqlConnection;
use Illuminate\Database\Query\Grammars\PostgresGrammar;
use Illuminate\Database\Query\Expression;

trait DBConnection
{
/**
* Run a select statement against the database and returns a generator.
*
* @param string $query
* @param array $bindings
* @param bool $useReadPdo
* @return \Generator
*/
public function cursor($query, $bindings = [], $useReadPdo = true)
{
$statement = $this->run($query, $bindings, function ($query, $bindings) use ($useReadPdo) {
if ($this->pretending()) {
return [];
}

if ($query instanceof Expression) {
$query = $query->getValue($this->getQueryGrammar());
}

// First we will create a statement for the query. Then, we will set the fetch
// mode and prepare the bindings for the query. Once that's done we will be
// ready to execute the query against the database and return the cursor.

$statement = $this->prepared($this->getPdoForSelect($useReadPdo)
->prepare($query));

$this->bindValues(
$statement, $this->prepareBindings($bindings)
);

// Next, we'll execute the query against the database and return the statement
// so we can return the cursor. The cursor will use a PHP generator to give
// back one row at a time without using a bunch of memory to render them.
$statement->execute();

return $statement;
});

while ($record = $statement->fetch()) {
yield $record;
}
}
}
2 changes: 1 addition & 1 deletion classes/db/DAO.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public function retrieve($sql, $params = [], $callHooks = true)
}
}

return DB::cursor(DB::raw($sql)->getValue(), $params);
return DB::cursor(DB::raw($sql)->getValue(DB::connection()->getQueryGrammar()), $params);
}

/**
Expand Down
6 changes: 5 additions & 1 deletion classes/mail/Mailable.php
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,11 @@ protected function addFooter(string $locale): self
protected function buildSubject($message): self
{
$this->subject ??= ''; // Allow email with empty subject if not set
$subject = app('mailer')->compileParams($this->subject, $this->viewData);
$withoutTagViewData = collect($this->viewData)
->map(fn(mixed $viewableData) => is_string($viewableData) ? strip_tags($viewableData) : $viewableData)
->toArray();

$subject = app('mailer')->compileParams($this->subject, $withoutTagViewData);
if (empty($subject)) {
trigger_error(
'You are sending ' . static::getName() ?? static::class . ' email with empty subject',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function up(): void
JOIN user_settings enabled_setting ON (enabled_setting.user_id = u.user_id AND enabled_setting.setting_name = 'apiKeyEnabled')
LEFT JOIN user_settings key_setting ON (key_setting.user_id = u.user_id AND key_setting.setting_name = 'apiKey')
WHERE key_setting.user_id IS NULL"
)
)->getValue(DB::connection()->getQueryGrammar())
);

collect($users)
Expand Down
1 change: 1 addition & 0 deletions classes/migration/upgrade/v3_4_0/PKPI7014_DoiMigration.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ protected function _migrateDoiSettingsToContext(): void
// Get plugin_based settings
$q = DB::table('plugin_settings')
->where('plugin_name', '=', 'doipubidplugin')
->where('context_id', '<>', 0)
->select(['context_id','setting_name', 'setting_value']);
$results = $q->get();

Expand Down
3 changes: 2 additions & 1 deletion classes/migration/upgrade/v3_4_0/PreflightCheckMigration.php
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,8 @@ protected function checkForeignKeySupport(): void
);

if (count($result) > 0) {
$tableNames = data_get($result, '*.TABLE_NAME');
error_log(print_r($result,true));
$tableNames = data_get($result, '*.table_name');
throw new Exception(
'Storage engine that doesn\'t support foreign key constraints detected in one or more tables: ' .
implode(', ', $tableNames) . '. Change to InnoDB before running the upgrade.'
Expand Down
2 changes: 1 addition & 1 deletion classes/security/Role.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class Role extends \PKP\core\DataObject
public const ROLE_ID_SUB_EDITOR = 17;
public const ROLE_ID_AUTHOR = 65536;
public const ROLE_ID_REVIEWER = 4096;
public const ROLE_ID_ASSISTANT = 4096;
public const ROLE_ID_ASSISTANT = 4097;
public const ROLE_ID_READER = 1048576;
public const ROLE_ID_SUBSCRIPTION_MANAGER = 2097152;

Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
"michelf/php-markdown": "1.*",
"slim/slim": "3.*",
"pimple/pimple": "3.*",
"laravel/framework": "^9.0",
"firebase/php-jwt": "5.*",
"laravel/framework": "^10.0",
"firebase/php-jwt": "6.*",
"adodb/adodb-php": "v5.20.18",
"gettext/gettext": "5.*",
"sokil/php-isocodes": "^4.1",
Expand Down Expand Up @@ -44,7 +44,7 @@
"component-dir": "lib/components",
"vendor-dir": "lib/vendor",
"platform": {
"php": "8.0.2"
"php": "8.1.0"
},
"allow-plugins": {
"cweagans/composer-patches": true,
Expand Down
Loading