Skip to content

Commit 57b5200

Browse files
committed
#10692 structured citations (development)
1 parent d043d72 commit 57b5200

File tree

3 files changed

+38
-6
lines changed

3 files changed

+38
-6
lines changed

classes/migration/install/MetadataMigration.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ public function up(): void
3030
$table->comment('A citation made by an associated publication.');
3131
$table->bigInteger('citation_id')->autoIncrement();
3232
$table->bigInteger('publication_id');
33-
$table->text('raw_citation')->nullable()->default(null);
3433
$table->bigInteger('seq')->default(0);
3534

3635
$table->foreign('publication_id', 'citations_publication')

classes/migration/upgrade/v3_5_0/I10692_CitationMigration.php

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
namespace PKP\migration\upgrade\v3_5_0;
1616

1717
use Illuminate\Database\Schema\Blueprint;
18-
use Illuminate\Support\Facades\Schema as Schema;
18+
use Illuminate\Support\Facades\DB;
19+
use Illuminate\Support\Facades\Schema;
1920
use PKP\install\DowngradeNotSupportedException;
2021
use PKP\migration\Migration;
2122

@@ -26,15 +27,19 @@ class I10692_CitationMigration extends Migration
2627
*/
2728
public function up(): void
2829
{
30+
$this->migrateRawCitations();
31+
32+
if (Schema::hasColumn('citations', 'raw_citation')) {
33+
Schema::table('citations', function (Blueprint $table) {
34+
$table->dropColumn('raw_citation');
35+
});
36+
}
37+
2938
if (Schema::hasColumn('citation_settings', 'setting_type')) {
3039
Schema::table('citation_settings', function (Blueprint $table) {
3140
$table->dropColumn('setting_type');
3241
});
3342
}
34-
35-
Schema::table('citations', function (Blueprint $table) {
36-
$table->text('raw_citation')->nullable()->default(null)->change();
37-
});
3843
}
3944

4045
/**
@@ -46,4 +51,31 @@ public function down(): void
4651
{
4752
throw new DowngradeNotSupportedException();
4853
}
54+
55+
/**
56+
* Migrates raw_citations from citations to citation_settings table.
57+
* This is needed because of multi-language support.
58+
*/
59+
public function migrateRawCitations(): void
60+
{
61+
$values = DB::table('citations as c')
62+
->select(
63+
'c.citation_id',
64+
's.locale',
65+
DB::raw("'raw_citation' as setting_name"),
66+
DB::raw("c.raw_citation as setting_value")
67+
)
68+
->distinct()
69+
->join('publications as p', 'c.publication_id', '=', 'p.publication_id')
70+
->join('submissions as s', 'p.submission_id', '=', 's.submission_id')
71+
->get()
72+
->map(function ($item) {
73+
return (array)$item;
74+
})
75+
->all();
76+
77+
DB::table('citation_settings')->upsert($values,
78+
['citation_id', 'locale', 'setting_name'],
79+
['setting_value']);
80+
}
4981
}

schemas/citation.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"rawCitation": {
2121
"type": "string",
2222
"description": "Optional metadata that contains references for works cited in this submission as raw text.",
23+
"multilingual": true,
2324
"validation": [
2425
"nullable"
2526
]

0 commit comments

Comments
 (0)