]> git.mxchange.org Git - friendica.git/blobdiff - src/BaseModel.php
Merge pull request #9819 from annando/issue-9814
[friendica.git] / src / BaseModel.php
index 791d6887c1702d088308bed27a4870b9c1766e0b..41320d8bd5bcf528529b9a6f623babf9bfe84508 100644 (file)
@@ -1,4 +1,23 @@
 <?php
+/**
+ * @copyright Copyright (C) 2020, Friendica
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
+ *
+ */
 
 namespace Friendica;
 
@@ -12,7 +31,7 @@ use Psr\Log\LoggerInterface;
  *
  * @property int id
  */
-abstract class BaseModel
+abstract class BaseModel extends BaseEntity
 {
        /** @var Database */
        protected $dba;
@@ -48,23 +67,9 @@ abstract class BaseModel
                $this->originalData = $data;
        }
 
-       /**
-        * Maps a data array (original/current) to a known field list of the chosen model
-        *
-        * This is useful to filter out additional attributes, which aren't part of the db-table (like readonly cached fields)
-        *
-        * @param array $data The data array to map to db-fields
-        *
-        * @return array the mapped data array
-        */
-       protected function mapFields(array $data)
-       {
-               return $data;
-       }
-
        public function getOriginalData()
        {
-               return $this->mapFields($this->originalData);
+               return $this->originalData;
        }
 
        public function resetOriginalData()
@@ -131,12 +136,12 @@ abstract class BaseModel
 
        public function toArray()
        {
-               return $this->mapFields($this->data);
+               return $this->data;
        }
 
        protected function checkValid()
        {
-               if (empty($this->data['id'])) {
+               if (!isset($this->data['id']) || is_null($this->data['id'])) {
                        throw new HTTPException\InternalServerErrorException(static::class . ' record uninitialized');
                }
        }