Skip to content

Commit d86e8e6

Browse files
committed
started adding plugin tests
1 parent 9d46713 commit d86e8e6

File tree

13 files changed

+230
-52
lines changed

13 files changed

+230
-52
lines changed

app/Http/Controllers/PluginController.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,6 @@ public function addMigrationToDatabase(Request $request, Plugin $plugin) {
237237
/**
238238
* Get the migration state for a plugin.
239239
*/
240-
241240
public function getMigrationState(Request $request, Plugin $plugin) {
242241
return response()->json($plugin->getMigrationState());
243242
}

app/PluginMigration.php

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ static function rollback(Plugin $plugin){
3535
}
3636

3737
static function exec(Plugin $plugin, $rollback = false){
38-
info("Running " . ($rollback ? "rollback" : "migrations") . " for plugin {$plugin->name}");
3938
//Determine the next batch number
4039
$nextBatch = PluginMigration::max('batch') + 1;
4140
$migrations = self::getMissingMigrations($plugin, $rollback);
@@ -79,6 +78,7 @@ static function getMigrationPath(Plugin $plugin): string {
7978
}
8079

8180
static function getMigrationState(Plugin $plugin): array {
81+
info("Getting migration state for plugin {$plugin->name}");
8282
$ranMigrations = PluginMigration::where('plugin_id', $plugin->id)
8383
->pluck('migration')
8484
->toArray();
@@ -114,22 +114,17 @@ static function getMissingMigrations(Plugin $plugin, $rollback = false): array {
114114

115115
static function getMigrationList(Plugin $plugin, $rollback = false){
116116
$path = self::getMigrationPath($plugin);
117-
info("Looking for migrations in $path");
117+
info("Getting migration list from path: $path");
118118
if(file_exists($path) && is_dir($path)) {
119119
$migrations = collect(File::files($path))->map(function($f) {
120-
info($f->getFilename());
121120
return $f->getFilename();
122121
});
123122

124-
info($migrations->toArray());
125-
126123
$migrations = $migrations->filter(function($f) {
127124
preg_match('/^(\d{4}_\d{2}_\d{2}_\d{6})_(.+)\.php$/', $f, $matches);
128125
return count($matches) == 3;
129126
});
130127

131-
info($migrations->toArray());
132-
133128
if($rollback) {
134129
$migrations = $migrations->sortDesc();
135130
} else {

config/app.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,18 @@
5454

5555
'url' => env('APP_URL', 'http://localhost'),
5656

57+
/*
58+
|--------------------------------------------------------------------------
59+
| Plugin Path
60+
|--------------------------------------------------------------------------
61+
|
62+
| This Path is used to determine where plugins are stored. It can be set
63+
| in the .env file using the APP_PLUGIN_PATH variable.
64+
| By default, it is set to app/Plugins.
65+
|
66+
*/
67+
'plugin_path' => env('APP_PLUGIN_PATH', 'app/Plugins'),
68+
5769
/*
5870
|--------------------------------------------------------------------------
5971
| Application Timezone
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
namespace Database\Seeders\Testing;
4+
5+
use Illuminate\Database\Seeder;
6+
use Illuminate\Support\Facades\DB;
7+
8+
class DatabaseTableSeeder extends Seeder
9+
{
10+
11+
/**
12+
* Auto generated seed file
13+
*
14+
* @return void
15+
*/
16+
public function run()
17+
{
18+
DB::table('plugins')->insert([
19+
[
20+
'id' => 1,
21+
'name' => 'Example',
22+
'installed_at' => null,
23+
'created_at' => '2024-02-05 12:00:00',
24+
'updated_at' => '2024-02-05 12:00:00',
25+
'version' => '1.0.0',
26+
'uuid' => 'bf7e2513-f408-4b2c-8057-23b49168172b'
27+
]
28+
]);
29+
}
30+
}

database/seeders/TestingSeeder.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Database\Seeders\General\RolesTableSeeder;
1717
use Database\Seeders\Testing\BibliographyTableSeeder;
1818
use Database\Seeders\Testing\CommentsSeeder;
19+
use Database\Seeders\Testing\DatabaseTableSeeder;
1920
use Database\Seeders\Testing\UserSeeder;
2021
use Illuminate\Database\Seeder;
2122
use Illuminate\Support\Facades\DB;
@@ -46,6 +47,7 @@ public function run() {
4647
$this->call(AttributeValuesTableSeeder::class);
4748
$this->call(ReferencesTableSeeder::class);
4849
$this->call(CommentsSeeder::class);
50+
$this->call(DatabaseTableSeeder::class);
4951

5052
// Set different root for tags
5153
DB::table('preferences')

resources/js/app.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ import { SpPS } from '@/bootstrap/plugins.js';
3535
import initGlobalComponents from '@/bootstrap/global-components.js';
3636
import initDirectives from '@/bootstrap/directives.js';
3737

38+
import "@milkdown/theme-nord/style.css";
39+
3840
const app = createApp(App);
3941
app.use(i18n);
4042
app.use(pinia);

resources/js/components/plugins/Plugin.vue

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -130,14 +130,16 @@
130130
import { isInstalled as isPluginInstalled } from '@/helpers/plugins.js';
131131
132132
import ChangelogTab from '@/components/plugins/tab/Changelog.vue';
133-
import MigrationTab from '@/components/plugins/tab/Migration.vue';
133+
import MigrationTab from '@/components/plugins/tab/Migration/Migration.vue';
134134
import InformationTab from './tab/Information.vue';
135+
import Switch from '../forms/Switch.vue';
135136
136137
export default {
137138
components: {
138139
ChangelogTab,
139-
MigrationTab,
140140
InformationTab,
141+
MigrationTab,
142+
Switch,
141143
},
142144
props: {
143145
value: {
@@ -148,6 +150,7 @@
148150
setup(props) {
149151
const { t } = useI18n();
150152
const page = ref('info');
153+
const installing = ref(false);
151154
152155
const sections = ['info', 'changelog', 'migrations'];
153156
@@ -162,26 +165,38 @@
162165
const showChangelog = _ => {
163166
showChangelogModal();
164167
};
165-
const install = _ => {
166-
systemStore.installPlugin(props.value.id);
168+
const install = async _ => {
169+
await systemStore.installPlugin(props.value.id);
167170
};
168-
const uninstall = _ => {
169-
systemStore.uninstallPlugin(props.value.id);
171+
const uninstall = async _ => {
172+
await systemStore.uninstallPlugin(props.value.id);
170173
};
171174
const remove = _ => {
172175
systemStore.removePlugin(props.value.id);
173176
};
174177
178+
const toggleActiveState = async (active) => {
179+
installing.value = true;
180+
if(isInstalled() !== active) {
181+
await install();
182+
} else {
183+
await uninstall();
184+
}
185+
installing.value = false;
186+
};
187+
175188
return {
176-
t,
177-
isInstalled,
178-
updateAvailable,
179-
showChangelog,
189+
installing,
180190
install,
181-
uninstall,
182-
remove,
191+
isInstalled,
183192
page,
193+
remove,
184194
sections,
195+
showChangelog,
196+
t,
197+
toggleActiveState,
198+
uninstall,
199+
updateAvailable,
185200
};
186201
}
187202
};

resources/js/components/plugins/tab/Migration.vue renamed to resources/js/components/plugins/tab/Migration/Migration.vue

Lines changed: 29 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -10,76 +10,63 @@
1010
v-else
1111
class="form-control"
1212
>
13-
<template v-if="migrationState.length == 0">
13+
<template v-if="noMigrations">
1414
{{ t('main.plugins.info.no_migrations') }}
1515
</template>
1616
<template v-else>
1717
<ul class="list-unstyled mb-0 overflow-x-auto">
1818
<li
19-
v-for="migration in migrationState"
19+
v-for="migration in migrationList"
2020
:key="migration.name"
2121
class="d-flex justify-content-between align-items-center mb-1"
2222
>
23-
<button
24-
v-if="migration.ran"
25-
class="btn btn-sm btn-outline-success border-0"
26-
disabled
27-
>
28-
<i
29-
v-if="migration.ran"
30-
class="fas fa-fw fa-check text-success"
31-
/>
32-
</button>
33-
<button
34-
v-else
35-
class="btn btn-sm btn-outline-danger"
36-
@click="addMigrationToDatabase(migration)"
37-
>
38-
<i
39-
class="fas fa-fw fa-times"
40-
:title="t('main.plugins.info.add_migration_to_db')"
41-
/>
42-
</button>
43-
44-
<span class="ms-3">{{ migration.name }}</span>
23+
<MigrationItem
24+
:migration="migration"
25+
@set="addMigrationToDatabase"
26+
/>
4527
</li>
4628
</ul>
4729
</template>
4830
</div>
4931
<div class="d-flex gap-2 flex-row-reverse">
5032
<button
5133
class="btn btn-sm btn-outline-secondary"
34+
:disabled="hasMissingMigrations"
5235
@click="migrate()"
5336
>
5437
{{ t('main.plugins.migrate') }}
5538
</button>
5639
<button
5740
class="btn btn-sm btn-outline-secondary"
41+
:disabled="noMigrations"
5842
@click="rollback()"
5943
>
6044
{{ t('main.plugins.rollback') }}
6145
</button>
6246

6347
<button
6448
class="btn btn-sm btn-outline-secondary"
49+
:disabled="noMigrations"
6550
@click="updateMigrationState()"
6651
>
6752
Check Migration
6853
</button>
6954
</div>
70-
71-
<alert :message="t('main.plugins.info.migration_notice')" />
7255
</div>
7356
</template>
7457

7558
<script>
76-
import { ref, onMounted } from 'vue';
59+
import { computed, ref, onMounted } from 'vue';
7760
import { useI18n } from 'vue-i18n';
7861
7962
// TODO:: move to api if still needed after rework
8063
import http from '@/bootstrap/http.js';
64+
import MigrationItem from './MigrationItem.vue';
8165
8266
export default {
67+
components: {
68+
MigrationItem,
69+
},
8370
props: {
8471
value: {
8572
type: Object,
@@ -88,7 +75,7 @@
8875
},
8976
setup(props) {
9077
const { t } = useI18n();
91-
const migrationState = ref([]);
78+
const migrationList = ref([]);
9279
const migrationLoaded = ref(false);
9380
9481
onMounted(() => {
@@ -101,7 +88,7 @@
10188
const result = await http.post(`/plugin/migrate/${props.value.id}/force_add`, {
10289
name: migration.name,
10390
});
104-
migrationState.value = result.data;
91+
migrationList.value = result.data;
10592
} catch(error) {
10693
console.error('Error adding migration to database', error);
10794
}
@@ -123,22 +110,32 @@
123110
const updateMigrationState = async _ => {
124111
try {
125112
const result = await http.get(`/plugin/migrate/${props.value.id}/check`);
126-
migrationState.value = result.data;
113+
migrationList.value = result.data;
127114
migrationLoaded.value = true;
128115
} catch(e) {
129116
console.error('Error fetching migration state', e);
130-
migrationState.value = [];
117+
migrationList.value = [];
131118
}
132119
};
133120
121+
const noMigrations = computed(() => {
122+
return migrationList.value.length === 0;
123+
});
124+
125+
const hasMissingMigrations = computed(() => {
126+
return migrationList.value.filter(m => !m.ran);
127+
});
128+
134129
return {
135130
t,
136131
addMigrationToDatabase,
137132
migrate,
138133
updateMigrationState,
139134
rollback,
140-
migrationState,
135+
migrationList,
141136
migrationLoaded,
137+
noMigrations,
138+
hasMissingMigrations,
142139
};
143140
}
144141
};
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<template>
2+
<button
3+
v-if="migration.ran"
4+
class="btn btn-sm btn-outline-success border-0"
5+
disabled
6+
>
7+
<i
8+
v-if="migration.ran"
9+
class="fas fa-fw fa-check text-success"
10+
/>
11+
</button>
12+
<button
13+
v-else
14+
class="btn btn-sm btn-outline-danger border-0"
15+
disabled=""
16+
>
17+
<i
18+
class="fas fa-fw fa-times"
19+
:title="t('main.plugins.info.add_migration_to_db')"
20+
/>
21+
</button>
22+
<button
23+
v-if="!migration.ran"
24+
class="btn btn-sm btn-outline-secondary"
25+
@click="$emit('set', migration)"
26+
:title="t('main.plugins.info.migration_notice')"
27+
>
28+
{{ t('global.set') }}
29+
</button>
30+
31+
<span class="ms-3 text-truncate">{{ migration.name }}</span>
32+
</template>
33+
34+
<script setup>
35+
36+
import { useI18n } from 'vue-i18n';
37+
const { t } = useI18n();
38+
39+
defineProps({
40+
migration: {
41+
type: Object,
42+
required: true,
43+
},
44+
});
45+
46+
const emit = defineEmits(['set']);
47+
48+
</script>
49+
50+
<style lang='scss' scoped></style>

0 commit comments

Comments
 (0)