aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJan-Hendrik Willms <tleilax+studip@gmail.com>2024-05-16 07:28:41 +0000
committerJan-Hendrik Willms <tleilax+studip@gmail.com>2024-05-16 07:28:41 +0000
commit6bc8e7bb6ff1b98f90ea605fde228c5e9d69d75d (patch)
treea103c55e0cf439844e3d68797f0cdd232b9ca60d /lib
parentf9cb99a85a578af3b168aad9be7792de5c8813ed (diff)
fixes #4138
Closes #4138 Merge request studip/studip!2980
Diffstat (limited to 'lib')
-rw-r--r--lib/migrations/Migration.php24
1 files changed, 21 insertions, 3 deletions
diff --git a/lib/migrations/Migration.php b/lib/migrations/Migration.php
index abaf747..92f73c7 100644
--- a/lib/migrations/Migration.php
+++ b/lib/migrations/Migration.php
@@ -49,6 +49,24 @@ abstract class Migration
}
/**
+ * Returns the name of the migration. If the migration is an anonymous
+ * class, the the name is created from the filename. Otherwise, it's the
+ * class name of the migration.
+ *
+ * @return string
+ */
+ public function getName(): string
+ {
+ $reflection = new ReflectionClass($this);
+ if ($reflection->isAnonymous()) {
+ $filename = basename($reflection->getFileName(), '.php');
+ $name = implode(' ', array_slice(explode('_', $filename), 1));
+ return ucfirst($name);
+ }
+ return static::class;
+ }
+
+ /**
* Abstract method performing this migration step.
* This method should be implemented in a migration subclass.
*/
@@ -67,12 +85,12 @@ abstract class Migration
/**
* Perform or revert this migration, depending on the indicated direction.
*
- * @param string $direction migration direction (either 'up' or 'down')
+ * @param ?string $direction migration direction (either 'up' or 'down')
*/
public function migrate($direction)
{
if (!in_array($direction, ['up', 'down'])) {
- return;
+ return null;
}
$result = $this->$direction();
@@ -107,7 +125,7 @@ abstract class Migration
$args = func_get_args();
$message = vsprintf(array_shift($args), $args);
- return $this->write($this->mark($message));
+ $this->write($this->mark($message));
}
/**