Browse Source

Fix Group\Save

INSERT query contained g_id = NULL.
Visman 3 years ago
parent
commit
2338592f55
1 changed files with 21 additions and 1 deletions
  1. 21 1
      app/Models/Group/Save.php

+ 21 - 1
app/Models/Group/Save.php

@@ -24,23 +24,31 @@ class Save extends Action
         if ($group->g_id < 1) {
         if ($group->g_id < 1) {
             throw new RuntimeException('The model does not have ID');
             throw new RuntimeException('The model does not have ID');
         }
         }
+
         $modified = $group->getModified();
         $modified = $group->getModified();
+
         if (empty($modified)) {
         if (empty($modified)) {
             return $group;
             return $group;
         }
         }
+
         $values = $group->getAttrs();
         $values = $group->getAttrs();
         $fileds = $this->c->dbMap->groups;
         $fileds = $this->c->dbMap->groups;
+
         $set = $vars = [];
         $set = $vars = [];
+
         foreach ($modified as $name) {
         foreach ($modified as $name) {
             if (! isset($fileds[$name])) {
             if (! isset($fileds[$name])) {
                 continue;
                 continue;
             }
             }
+
             $vars[] = $values[$name];
             $vars[] = $values[$name];
             $set[]  = $name . '=?' . $fileds[$name];
             $set[]  = $name . '=?' . $fileds[$name];
         }
         }
+
         if (empty($set)) {
         if (empty($set)) {
             return $group;
             return $group;
         }
         }
+
         $vars[] = $group->g_id;
         $vars[] = $group->g_id;
 
 
         $set   = \implode(', ', $set);
         $set   = \implode(', ', $set);
@@ -49,6 +57,7 @@ class Save extends Action
             WHERE g_id=?i";
             WHERE g_id=?i";
 
 
         $this->c->DB->exec($query, $vars);
         $this->c->DB->exec($query, $vars);
+
         $group->resModified();
         $group->resModified();
 
 
         // сбросить кеш для гостя
         // сбросить кеш для гостя
@@ -67,27 +76,38 @@ class Save extends Action
         if (null !== $group->g_id) {
         if (null !== $group->g_id) {
             throw new RuntimeException('The model has ID');
             throw new RuntimeException('The model has ID');
         }
         }
+
         $attrs  = $group->getAttrs();
         $attrs  = $group->getAttrs();
         $fileds = $this->c->dbMap->groups;
         $fileds = $this->c->dbMap->groups;
+
         $set = $set2 = $vars = [];
         $set = $set2 = $vars = [];
+
         foreach ($attrs as $key => $value) {
         foreach ($attrs as $key => $value) {
-            if (! isset($fileds[$key])) {
+            if (
+                ! isset($fileds[$key])
+                || 'g_id' === $key
+            ) {
                 continue;
                 continue;
             }
             }
+
             $vars[] = $value;
             $vars[] = $value;
             $set[]  = $key;
             $set[]  = $key;
             $set2[] = '?' . $fileds[$key];
             $set2[] = '?' . $fileds[$key];
         }
         }
+
         if (empty($set)) {
         if (empty($set)) {
             throw new RuntimeException('The model is empty');
             throw new RuntimeException('The model is empty');
         }
         }
+
         $set   = \implode(', ', $set);
         $set   = \implode(', ', $set);
         $set2  = \implode(', ', $set2);
         $set2  = \implode(', ', $set2);
         $query = "INSERT INTO ::groups ({$set})
         $query = "INSERT INTO ::groups ({$set})
             VALUES ({$set2})";
             VALUES ({$set2})";
 
 
         $this->c->DB->exec($query, $vars);
         $this->c->DB->exec($query, $vars);
+
         $group->g_id = (int) $this->c->DB->lastInsertId();
         $group->g_id = (int) $this->c->DB->lastInsertId();
+
         $group->resModified();
         $group->resModified();
 
 
         return $group->g_id;
         return $group->g_id;