Check for `IDefaultValueDatabaseTableColumn` in AbstractDatabaseTableColumn
authorTim Düsterhus <duesterhus@woltlab.com>
Mon, 11 Apr 2022 12:14:48 +0000 (14:14 +0200)
committerTim Düsterhus <duesterhus@woltlab.com>
Mon, 11 Apr 2022 12:19:20 +0000 (14:19 +0200)
wcfsetup/install/files/lib/system/database/table/column/AbstractDatabaseTableColumn.class.php
wcfsetup/install/files/lib/system/database/table/column/IDatabaseTableColumn.class.php

index 362efcb3c79fb9fd1e111151c63ca18c26825e04..d970e3f4ec247a3a11874cc9edd8a6a4fe78e042 100644 (file)
@@ -48,15 +48,22 @@ abstract class AbstractDatabaseTableColumn implements IDatabaseTableColumn, IDef
     public function getData()
     {
         $data = [
-            'default' => $this->getDefaultValue() !== null ? "'" . \str_replace(
-                ["'", '\\'],
-                ["''", '\\\\'],
-                $this->getDefaultValue()
-            ) . "'" : null,
             'notNull' => $this->isNotNull() ? 1 : 0,
             'type' => $this->getType(),
         ];
 
+        if ($this instanceof IDefaultValueDatabaseTableColumn) {
+            if ($this->getDefaultValue() !== null) {
+                $data['default'] = "'" . \str_replace(
+                    ["'", '\\'],
+                    ["''", '\\\\'],
+                    $this->getDefaultValue()
+                ) . "'";
+            } else {
+                $data['default'] = null;
+            }
+        }
+
         if ($this instanceof IAutoIncrementDatabaseTableColumn) {
             $data['autoIncrement'] = $this->isAutoIncremented() ? 1 : 0;
 
@@ -183,9 +190,12 @@ abstract class AbstractDatabaseTableColumn implements IDatabaseTableColumn, IDef
     public static function createFromData($name, array $data)
     {
         $column = static::create($name)
-            ->defaultValue($data['default'])
             ->notNull($data['notNull']);
 
+        if ($column instanceof IDefaultValueDatabaseTableColumn) {
+            $column->defaultValue($data['default']);
+        }
+
         if ($column instanceof IAutoIncrementDatabaseTableColumn) {
             $column->autoIncrement($data['autoIncrement'] ?: null);
         }
index 3ffcbe68eb2ac82ed97db33825e15638d53d31e5..37f3c70c7f1f0ecc7bbe111768b7cadaef0c05ed 100644 (file)
@@ -13,14 +13,6 @@ namespace wcf\system\database\table\column;
  */
 interface IDatabaseTableColumn
 {
-    /**
-     * Sets the default value of the column and returns the column.
-     *
-     * @param mixed $defaultValue
-     * @return  $this
-     */
-    public function defaultValue($defaultValue);
-
     /**
      * Marks the column to be dropped and returns the column.
      *
@@ -35,13 +27,6 @@ interface IDatabaseTableColumn
      */
     public function getData();
 
-    /**
-     * Returns the default value of the column.
-     *
-     * @return  mixed
-     */
-    public function getDefaultValue();
-
     /**
      * Returns the name of the column.
      *