function save() { if (!$this->validate() && substr($this->schema->table, -5) !== '_i18n') { $msg = i18n::get('Trying to save invalid content for model "%0"', $this); debug::error($msg, 1); $this->dump(); return false; } $primaryKey = $this->schema->getPrimaryKey()->name; // No need to save if the model has a PK set and is synced with the DB if ($this->{$primaryKey} && $this->is_synced) { return null; } $sql = $this->getSaveQuery(); if (!self::$_DB) { self::$_DB = new MySQL(); } self::$_DB->query($sql); if (!$this->{$primaryKey} && !$this->is_synced) { //Update the PrimaryKey $insertId = self::$_DB->insert_id(); $this->_synced_data[$primaryKey] = $insertId; $this->_data[$primaryKey] = $insertId; } // Save the localized versions too if (Kennel::getSetting('i18n', 'enabled') && substr($this->model_name, -5) !== '_i18n') { foreach ($this->_i18n as $i18n) { // Set the relationship IDs if ($i18n->__get("{$this->model_name}_{$primaryKey}") !== $this->{$primaryKey}) { } $i18n->__set("{$this->model_name}_{$primaryKey}", $this->{$primaryKey}); $i18n->save(); } } // Update the synced data $this->_synced_data = $this->_data; $this->is_synced = true; return true; }