Skip to content

Commit

Permalink
pkp/pkp-lib#9892 upgrade to laravel 11 and PHP 8.2+
Browse files Browse the repository at this point in the history
  • Loading branch information
touhidurabir authored and asmecher committed Aug 12, 2024
1 parent fdc603a commit fc34c9f
Show file tree
Hide file tree
Showing 12 changed files with 74 additions and 120 deletions.
29 changes: 13 additions & 16 deletions classes/migration/install/MetricsMigration.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,16 +195,15 @@ public function up(): void
$table->integer('metric_unique');

$table->index(['context_id', 'submission_id'], 'msgd_context_id_submission_id');
switch (DB::getDriverName()) {
case 'mysql':
match (DB::getDriverName()) {
'mysql', 'mariadb' =>
// See "Create a database table" here: https://db-ip.com/db/format/ip-to-city-lite/csv.html
// where city is defined as varchar(80)
$table->unique([DB::raw('load_id, context_id, submission_id, country, region, city(80), date')], 'msgd_uc_load_context_submission_c_r_c_date');
break;
case 'pgsql':
$table->unique(['load_id', 'context_id', 'submission_id', 'country', 'region', 'city', 'date'], 'msgd_uc_load_context_submission_c_r_c_date');
break;
}
$table->unique([DB::raw('load_id, context_id, submission_id, country, region, city(80), date')], 'msgd_uc_load_context_submission_c_r_c_date'),

'pgsql' =>
$table->unique(['load_id', 'context_id', 'submission_id', 'country', 'region', 'city', 'date'], 'msgd_uc_load_context_submission_c_r_c_date'),
};
});

Schema::create('metrics_submission_geo_monthly', function (Blueprint $table) {
Expand All @@ -227,16 +226,14 @@ public function up(): void
$table->integer('metric_unique');

$table->index(['context_id', 'submission_id'], 'msgm_context_id_submission_id');
switch (DB::getDriverName()) {
case 'mysql':
match (DB::getDriverName()) {
'mysql', 'mariadb' =>
// See "Create a database table" here: https://db-ip.com/db/format/ip-to-city-lite/csv.html
// where city is defined as varchar(80)
$table->unique([DB::raw('context_id, submission_id, country, region, city(80), month')], 'msgm_uc_context_submission_c_r_c_month');
break;
case 'pgsql':
$table->unique(['context_id', 'submission_id', 'country', 'region', 'city', 'month'], 'msgm_uc_context_submission_c_r_c_month');
break;
}
$table->unique([DB::raw('context_id, submission_id, country, region, city(80), month')], 'msgm_uc_context_submission_c_r_c_month'),
'pgsql' =>
$table->unique(['context_id', 'submission_id', 'country', 'region', 'city', 'month'], 'msgm_uc_context_submission_c_r_c_month'),
};
});

// Usage stats total item temporary records
Expand Down
16 changes: 8 additions & 8 deletions classes/migration/install/OPSMigration.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function up(): void
$table->foreign('review_form_id')->references('review_form_id')->on('review_forms')->onDelete('set null');
$table->index(['review_form_id'], 'sections_review_form_id');

$table->float('seq', 8, 2)->default(0);
$table->float('seq')->default(0);
$table->tinyInteger('editor_restricted')->default(0);
$table->tinyInteger('meta_indexed')->default(0);
$table->tinyInteger('meta_reviewed')->default(1);
Expand Down Expand Up @@ -122,7 +122,7 @@ public function up(): void
$table->foreign('submission_file_id')->references('submission_file_id')->on('submission_files')->onDelete('SET NULL');
$table->index(['submission_file_id'], 'publication_galleys_submission_file_id');

$table->float('seq', 8, 2)->default(0);
$table->float('seq')->default(0);
$table->string('remote_url', 2047)->nullable();
$table->tinyInteger('is_approved')->default(0);

Expand Down Expand Up @@ -152,12 +152,12 @@ public function up(): void


// Add partial index (DBMS-specific)
switch (DB::getDriverName()) {
case 'mysql': DB::unprepared('CREATE INDEX publication_galley_settings_name_value ON publication_galley_settings (setting_name(50), setting_value(150))');
break;
case 'pgsql': DB::unprepared('CREATE INDEX publication_galley_settings_name_value ON publication_galley_settings (setting_name, setting_value)');
break;
}
match (DB::getDriverName()) {
'mysql', 'mariadb' =>
DB::unprepared('CREATE INDEX publication_galley_settings_name_value ON publication_galley_settings (setting_name(50), setting_value(150))'),
'pgsql' =>
DB::unprepared('CREATE INDEX publication_galley_settings_name_value ON publication_galley_settings (setting_name, setting_value)'),
};
}

/**
Expand Down
2 changes: 1 addition & 1 deletion classes/migration/install/ServersMigration.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function up(): void
$table->comment('A list of preprint servers managed by the installation.');
$table->bigInteger('server_id')->autoIncrement();
$table->string('path', 32);
$table->float('seq', 8, 2)->default(0)->comment('Used to order lists of servers');
$table->float('seq')->default(0)->comment('Used to order lists of servers');
$table->string('primary_locale', 28);
$table->tinyInteger('enabled')->default(1)->comment('Controls whether or not the server is considered "live" and will appear on the website. (Note that disabled servers may still be accessible, but only if the user knows the URL.)');
$table->unique(['path'], 'servers_path');
Expand Down
3 changes: 1 addition & 2 deletions classes/migration/upgrade/v3_4_0/I6093_AddForeignKeys.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
namespace APP\migration\upgrade\v3_4_0;

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;

class I6093_AddForeignKeys extends \PKP\migration\upgrade\v3_4_0\I6093_AddForeignKeys
Expand Down Expand Up @@ -49,7 +48,7 @@ public function up(): void
});

// Attempt to drop the previous foreign key, which doesn't have the cascade rule
if (DB::getDoctrineSchemaManager()->introspectTable('publication_galleys')->hasForeignKey('publication_galleys_submission_file_id_foreign')) {
if ($this->hasForeignKey('publication_galleys', 'publication_galleys_submission_file_id_foreign')) {
Schema::table('publication_galleys', fn (Blueprint $table) => $table->dropForeign('publication_galleys_submission_file_id_foreign'));
}

Expand Down
2 changes: 1 addition & 1 deletion classes/migration/upgrade/v3_4_0/I6759_RenameVariables.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ private function _updateTablesWithReference()

Schema::table('servers', function (Blueprint $table) {
$table->renameColumn('journal_id', 'server_id');
$table->float('seq', 8, 2)->comment('Used to order lists of servers')->change();
$table->float('seq')->comment('Used to order lists of servers')->change();
$table->smallInteger('enabled')->default(1)->comment('Controls whether or not the server is considered "live" and will appear on the website. (Note that disabled servers may still be accessible, but only if the user knows the URL.)')->change();
$table->unique(['path'], 'servers_path');
});
Expand Down
28 changes: 12 additions & 16 deletions classes/migration/upgrade/v3_4_0/I9231_FixMetricsIndexes.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,25 +51,21 @@ public function up(): void
// and create new ones using city column prefix for MySQL
Schema::table('metrics_submission_geo_daily', function (Blueprint $table) {
$table->dropUnique('msgd_uc_load_context_submission_c_r_c_date');
switch (DB::getDriverName()) {
case 'mysql':
$table->unique([DB::raw('load_id, context_id, submission_id, country, region, city(80), date')], 'msgd_uc_load_context_submission_c_r_c_date');
break;
case 'pgsql':
$table->unique(['load_id', 'context_id', 'submission_id', 'country', 'region', 'city', 'date'], 'msgd_uc_load_context_submission_c_r_c_date');
break;
}
match (DB::getDriverName()) {
'mysql', 'mariadb' =>
$table->unique([DB::raw('load_id, context_id, submission_id, country, region, city(80), date')], 'msgd_uc_load_context_submission_c_r_c_date'),
'pgsql' =>
$table->unique(['load_id', 'context_id', 'submission_id', 'country', 'region', 'city', 'date'], 'msgd_uc_load_context_submission_c_r_c_date'),
};
});
Schema::table('metrics_submission_geo_monthly', function (Blueprint $table) {
$table->dropUnique('msgm_uc_context_submission_c_r_c_month');
switch (DB::getDriverName()) {
case 'mysql':
$table->unique([DB::raw('context_id, submission_id, country, region, city(80), month')], 'msgm_uc_context_submission_c_r_c_month');
break;
case 'pgsql':
$table->unique(['context_id', 'submission_id', 'country', 'region', 'city', 'month'], 'msgm_uc_context_submission_c_r_c_month');
break;
}
match (DB::getDriverName()) {
'mysql', 'mariadb' =>
$table->unique([DB::raw('context_id, submission_id, country, region, city(80), month')], 'msgm_uc_context_submission_c_r_c_month'),
'pgsql' =>
$table->unique(['context_id', 'submission_id', 'country', 'region', 'city', 'month'], 'msgm_uc_context_submission_c_r_c_month'),
};
});
}

Expand Down
4 changes: 2 additions & 2 deletions classes/migration/upgrade/v3_4_0/ReviewFormsMigration.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function up(): void
$table->bigInteger('review_form_id')->autoIncrement();
$table->bigInteger('assoc_type');
$table->bigInteger('assoc_id');
$table->float('seq', 8, 2)->nullable();
$table->float('seq')->nullable();
$table->smallInteger('is_active')->nullable();
});
}
Expand All @@ -54,7 +54,7 @@ public function up(): void
Schema::create('review_form_elements', function (Blueprint $table) {
$table->bigInteger('review_form_element_id')->autoIncrement();
$table->bigInteger('review_form_id');
$table->float('seq', 8, 2)->nullable();
$table->float('seq')->nullable();
$table->bigInteger('element_type')->nullable();
$table->smallInteger('required')->nullable();
$table->smallInteger('included')->nullable();
Expand Down
1 change: 1 addition & 0 deletions dbscripts/xml/upgrade.xml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
<migration class="APP\migration\upgrade\v3_4_0\I8151_ExtendSettingValues"/>
<migration class="PKP\migration\upgrade\v3_4_0\I8151_ExtendSettingValues"/>
<migration class="PKP\migration\upgrade\v3_4_0\I7366_UpdateUserAPIKeySettings"/>
<migration class="PKP\migration\upgrade\v3_4_0\I7463_LocaleColumn"/>
<migration class="PKP\migration\upgrade\v3_4_0\I8093_UpdateUserGroupRelationTablesFK"/>
<migration class="APP\migration\upgrade\v3_4_0\I7796_UpdateCrossrefSchema"/>
<migration class="PKP\migration\upgrade\v3_4_0\I7287_RemoveEmailTemplatesDefault"/>
Expand Down
39 changes: 19 additions & 20 deletions plugins/oaiMetadataFormats/dc/tests/OAIMetadataFormat_DCTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
use APP\server\Server;
use APP\submission\Submission;
use Illuminate\Support\LazyCollection;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\MockObject\MockObject;
use PKP\core\Dispatcher;
use PKP\core\Registry;
Expand All @@ -47,6 +48,8 @@
use PKP\submission\SubmissionSubjectDAO;
use PKP\tests\PKPTestCase;

#[CoversClass(OAIMetadataFormat_DC::class)]
#[CoversClass(\APP\plugins\metadata\dc11\filter\Dc11SchemaPreprintAdapter::class)]
class OAIMetadataFormat_DCTest extends PKPTestCase
{
/**
Expand All @@ -65,10 +68,6 @@ protected function getMockedRegistryKeys(): array
return [...parent::getMockedRegistryKeys(), 'request'];
}

/**
* @covers OAIMetadataFormat_DC
* @covers \APP\plugins\metadata\dc11\filter\Dc11SchemaPreprintAdapter
*/
public function testToXml()
{
//
Expand Down Expand Up @@ -114,14 +113,14 @@ public function testToXml()
->getMock();
$preprint->expects($this->any())
->method('getBestId')
->will($this->returnValue(9));
->willReturn(9);
$preprint->setData('locale', 'en');
$preprint->setId(9);
$preprint->setData('contextId', $serverId);
$author->setSubmissionId($preprint->getId());
$preprint->expects($this->any())
->method('getCurrentPublication')
->will($this->returnValue($publication));
->willReturn($publication);

/** @var Doi|MockObject */
$galleyDoiObject = $this->getMockBuilder(Doi::class)
Expand All @@ -138,10 +137,10 @@ public function testToXml()
->getMock();
$galley->expects(self::any())
->method('getFileType')
->will($this->returnValue('galley-filetype'));
->willReturn('galley-filetype');
$galley->expects(self::any())
->method('getBestGalleyId')
->will($this->returnValue(98));
->willReturn(98);
$galley->setId(98);
$galley->setData('doiObject', $galleyDoiObject);
$galley->setData('locale', 'en');
Expand All @@ -156,7 +155,7 @@ public function testToXml()
$server->expects($this->any())
->method('getSetting')
->with('publishingMode')
->will($this->returnValue(Server::PUBLISHING_MODE_OPEN));
->willReturn(Server::PUBLISHING_MODE_OPEN);
$server->setName('server-title', 'en');
$server->setData('publisherInstitution', 'server-publisher');
$server->setPrimaryLocale('en');
Expand All @@ -183,27 +182,27 @@ public function testToXml()
$router->setApplication($application);
$router->expects($this->any())
->method('url')
->will($this->returnCallback(fn ($request, $newContext = null, $handler = null, $op = null, $path = null) => $handler . '-' . $op . '-' . implode('-', $path)));
->willReturnCallback(fn ($request, $newContext = null, $handler = null, $op = null, $path = null) => $handler . '-' . $op . '-' . implode('-', $path));

// Dispatcher
/** @var Dispatcher|MockObject */
$dispatcher = $this->getMockBuilder(Dispatcher::class)
->onlyMethods(['url'])
->getMock();
->onlyMethods(['url'])
->getMock();
$dispatcher->expects($this->any())
->method('url')
->will($this->returnCallback(fn ($request, $shortcut, $newContext = null, $handler = null, $op = null, $path = null) => $handler . '-' . $op . '-' . implode('-', $path)));
->willReturnCallback(fn ($request, $shortcut, $newContext = null, $handler = null, $op = null, $path = null) => $handler . '-' . $op . '-' . implode('-', $path));

// Request
$requestMock = $this->getMockBuilder(Request::class)
->onlyMethods(['getRouter', 'getDispatcher'])
->getMock();
$requestMock->expects($this->any())
->method('getRouter')
->will($this->returnValue($router));
->willReturn($router);
$requestMock->expects($this->any())
->method('getDispatcher')
->will($this->returnValue($dispatcher));
->willReturn($dispatcher);
Registry::set('request', $requestMock);


Expand All @@ -217,10 +216,10 @@ public function testToXml()
->getMock();
$oaiDao->expects($this->any())
->method('getServer')
->will($this->returnValue($server));
->willReturn($server);
$oaiDao->expects($this->any())
->method('getSection')
->will($this->returnValue($section));
->willReturn($section);
DAORegistry::registerDAO('OAIDAO', $oaiDao);

/** @var GalleyCollector|MockObject */
Expand All @@ -230,7 +229,7 @@ public function testToXml()
->getMock();
$mockGalleyCollector->expects($this->any())
->method('getMany')
->will($this->returnValue(LazyCollection::wrap($galleys)));
->willReturn(LazyCollection::wrap($galleys));
app()->instance(GalleyCollector::class, $mockGalleyCollector);

// Mocked DAO to return the subjects
Expand All @@ -239,7 +238,7 @@ public function testToXml()
->getMock();
$submissionSubjectDao->expects($this->any())
->method('getSubjects')
->will($this->returnValue(['en' => ['preprint-subject', 'preprint-subject-class']]));
->willReturn(['en' => ['preprint-subject', 'preprint-subject-class']]);
DAORegistry::registerDAO('SubmissionSubjectDAO', $submissionSubjectDao);

// Mocked DAO to return the keywords
Expand All @@ -248,7 +247,7 @@ public function testToXml()
->getMock();
$submissionKeywordDao->expects($this->any())
->method('getKeywords')
->will($this->returnValue(['en' => ['preprint-keyword']]));
->willReturn(['en' => ['preprint-keyword']]);
DAORegistry::registerDAO('SubmissionKeywordDAO', $submissionKeywordDao);

//
Expand Down
Loading

0 comments on commit fc34c9f

Please sign in to comment.