Saves post modules
@return boolean
770236
public function savePost()
    {
        $key = $_REQUEST['id'];

        if (is_numeric($key)) {
            return $this->saveAsPostMeta($key);
        }

        if (\Modularity\Helper\Post::isArchive()) {
            global $archive;
            $key = $archive;
        }

        return $this->saveAsOption($key);
    }
1189029
public function save()
        {
            $query = [];

            // remove any expression fields as they are already baked into the query
            $values = array_values(array_diff_key($this->_dirty_fields, $this->_expr_fields));

            if (!$this->_is_new) { // UPDATE
                // If there are no dirty values, do nothing
                if (empty($values) && empty($this->_expr_fields)) {
                    return true;
                }

                $query = $this->_buildUpdate();
                $id = $this->id(true);

                if (Arrays::is($id)) {
                    $values = array_merge($values, array_values($id));
                } else {
                    $values[] = $id;
                }
            } else { // INSERT
                $query = $this->_buildInsert();
            }

            $success = self::_execute($query, $values, $this->_connection_name);
            $caching_auto_clear_enabled = self::$_config[$this->_connection_name]['caching_auto_clear'];

            if ($caching_auto_clear_enabled){
                self::clear_cache($this->_table_name, $this->_connection_name);
            }

            // If we've just inserted a new record, set the ID of this object
            if ($this->_is_new) {
                $this->_is_new = false;

                if ($this->count_null_id_columns() != 0) {
                    $db = self::get_db($this->_connection_name);

                    if($db->getAttribute(PDO::ATTR_DRIVER_NAME) == 'pgsql') {
                        // it may return several columns if a compound primary
                        // key is used
                        $row = self::get_last_statement()->fetch(PDO::FETCH_ASSOC);

                        foreach($row as $key => $value) {
                            $this->_data[$key] = $value;
                        }
                    } else {
                        $column = $this->_getIdColumnName();
                        // if the primary key is compound, assign the last inserted id
                        // to the first column

                        if (Arrays::is($column)) {
                            $column = array_slice($column, 0, 1);
                        }

                        $this->_data[$column] = $db->lastInsertId();
                    }
                }
            }

            $this->_dirty_fields = $this->_expr_fields = [];

            return $success;
        }
1320944
public function upload(): bool
    {
        $saved = $this->save();

        // ignore saving error
        $this->uploadFile($this->aliasConfig->getFileDirectory($this), $this->aliasConfig->getFileName($this));

        return $saved;
    }
1262793
public function save()
    {
        parent::save();

        $soxId = $this->getEditObjectId();

        if (!$this->_allowAdminEdit($soxId)) {
            return false;
        }

        $aParams = \OxidEsales\Eshop\Core\Registry::getConfig()->getRequestParameter("editval");

        $oUser = oxNew(\OxidEsales\Eshop\Application\Model\User::class);
        if ($soxId != "-1") {
            $oUser->load($soxId);
        } else {
            $aParams['oxuser__oxid'] = null;
        }

        // checkbox handling
        $aParams['oxuser__oxactive'] = $oUser->oxuser__oxactive->value;

        $blNewsParams = \OxidEsales\Eshop\Core\Registry::getConfig()->getRequestParameter("editnews");
        if (isset($blNewsParams)) {
            $oNewsSubscription = $oUser->getNewsSubscription();
            $oNewsSubscription->setOptInStatus((int) $blNewsParams);
            $oNewsSubscription->setOptInEmailStatus((int) \OxidEsales\Eshop\Core\Registry::getConfig()->getRequestParameter("emailfailed"));
        }

        $oUser->assign($aParams);
        $oUser->save();

        // set oxid if inserted
        $this->setEditObjectId($oUser->getId());
    }
133055
public function actionSave()
    {
        if(Yii::$app->request->isAjax)
        {
            $p = Yii::$app->request->post();
            // after find there are old values (see modules/OneFile::afterFind())
            $model = OneFile::findOne($p['file_id']);
            // so, change them for new defs (see modules/OneFile::beforeSave())
            $model->vars = json_decode($p['defs']);
            $model->save(false, ['defs']);
            
            echo $p['file_id'];
        }
    }
1238560
public function save() {
		if (!isset($this->new_album)) {
			$this->new_album = 1;
		}

		if (!isset($this->last_notified)) {
			$this->last_notified = 0;
		}

		if (!parent::save()) {
			return false;
		}

		mkdir(tp_get_img_dir($this->guid), 0755, true);

		return true;
	}
232109
public function saveHideTitleCheckbox($postId, $post)
    {
        if (substr($post->post_type, 0, 4) != 'mod-') {
            return;
        }

        if (!isset($_POST['modularity-module-hide-title'])) {
            update_post_meta($post->ID, 'modularity-module-hide-title', 0);
            return;
        }

        update_post_meta($post->ID, 'modularity-module-hide-title', 1);
        return;
    }
981598
public function save_options() {
		if ( ! filter_input( INPUT_POST, 'submit' ) ) {
			return false;
		}

		if ( ! wp_verify_nonce( filter_input( INPUT_POST, '_wpnonce' ), 'update-permalink' ) ) {
			return false;
		}

		if ( false === strpos( filter_input( INPUT_POST, '_wp_http_referer' ), 'options-permalink.php' ) ) {
			return false;
		}

		$post_types = CPTP_Util::get_post_types();

		foreach ( $post_types as $post_type ) :

			$structure = trim( esc_attr( filter_input( INPUT_POST, $post_type . '_structure' ) ) ); // get setting.

			// default permalink structure.
			if ( ! $structure ) {
				$structure = CPTP_DEFAULT_PERMALINK;
			}

			$structure = str_replace( '//', '/', '/' . $structure );// first "/"
			// last "/".
			$lastString = substr( trim( esc_attr( filter_input( INPUT_POST,'permalink_structure' ) ) ), - 1 );
			$structure  = rtrim( $structure, '/' );

			if ( '/' === $lastString ) {
				$structure = $structure . '/';
			}

			update_option( $post_type . '_structure', $structure );
		endforeach;
		$no_taxonomy_structure = ! filter_input( INPUT_POST, 'no_taxonomy_structure' );
		$add_post_type_for_tax = filter_input( INPUT_POST, 'add_post_type_for_tax' );

		update_option( 'no_taxonomy_structure', $no_taxonomy_structure );
		update_option( 'add_post_type_for_tax', $add_post_type_for_tax );
		update_option( 'cptp_permalink_checked', CPTP_VERSION );
	}
40511
public function save()
	{
		if ( ! $this->is_loaded() ) return false;

		$this->fill_defaults();

		$error = null;

		$id = wp_insert_post( $this->attributes, $error );

		if ( ! empty( $id ) ) {

			$this->attributes['ID'] = $id;

			$this->save_meta_all();

		}

		return $error === false ? true : $error;
	}
1303452
protected function save()
    {
        $filename = Path::create([$this->outputPath(), $this->outputFile()]);

        return (bool) \file_put_contents($filename->toString(), $this->stub);
    }
819335
public function saveConfig() {
		try {
			foreach(Tree::getAll() as $tree){		
				if(Auth::isManager($tree)){
					$tree_enabled = Filter::postInteger('HEALTHCHECK_ENABLED_' . $tree->getTreeId(), 0, 1);
					$tree->setPreference('MAJ_AT_'.$this->getName().'_ENABLED', $tree_enabled);
				}
			}
			return true;
		}
		catch (\Exception $ex) {
			Log::addErrorLog(sprintf('Error while updating the Admin Task "%s". Exception: %s', $this->getName(), $ex->getMessage()));
			return false;
		}
	}
999990
public function save()
	{
		$this->db->begin();
		foreach($this->data as $item)
		{
			$this->db->insert($this->tableName,$item);
		}
		$this->db->commit();
		return true;
	}
190153
public function save()
    {
        if ($this->validate()) {
            $manager = Configs::authManager();
            $class = $this->className;
            if ($this->_item === null) {
                $this->_item = new $class();
                $isNew = true;
            } else {
                $isNew = false;
                $oldName = $this->_item->name;
            }
            $this->_item->name = $this->name;

            if ($isNew) {
                $manager->add($this->_item);
            } else {
                $manager->update($oldName, $this->_item);
            }

            return true;
        } else {
            return false;
        }
    }
734444
public function saveSiteAction()
    {
        $request = $this->getRequest();
        $siteId = $request->getPost('site_id', null);
        $status  = 0;
        $errors  = array();
        $textMessage = '';
        $textTitle = '';
        
        $this->getEventManager()->trigger('meliscms_site_save_start', $this, array());
        
        $translator = $this->getServiceLocator()->get('translator');
        $melisTool = $this->getServiceLocator()->get('MelisCoreTool');
        $melisTool->setMelisToolKey(self::TOOL_INDEX, self::TOOL_KEY);
       
        // Getting the Creation/Edition Site Form
        if (is_null($siteId))
        {
            $siteFormType = 'meliscms_site_tool_creation_form';
            $logTypeCode = 'CMS_SITE_ADD';
        }
        else
        {
            $siteFormType = 'meliscms_site_tool_edition_form';
            $logTypeCode = 'CMS_SITE_UPDATE';
        }
        
        $siteForm = $melisTool->getForm($siteFormType);
        
        if($request->isPost()) 
        {
            $siteTable = $this->getServiceLocator()->get('MelisEngineTableSite');
            $domainTable = $this->getServiceLocator()->get('MelisEngineTableSiteDomain');
            $site404Table = $this->getServiceLocator()->get('MelisEngineTableSite404');
            
            $postValues = get_object_vars($request->getPost());
            $postValues = $melisTool->sanitizePost($postValues);
            $siteForm->setData($postValues);
            
            
            
            if($siteForm->isValid()) 
            {
                $data = $siteForm->getData();
                
                $dataSite = array();
                $dataDomain = array();
                $dataSite404 = array();
                $dataSiteLang= null;
                
                if (!empty($data['plang_lang_id'])){
                    $dataSiteLang = $data['plang_lang_id'];
                }
                
                foreach($data as $dataKey => $dataValue) 
                {
                    if(strpos($dataKey, self::SITE_TABLE_PREFIX) !== false) {
                        $dataSite[$dataKey] = $data[$dataKey];
                    }
                    
                    if(strpos($dataKey, self::SITE404_TABLE_PREFIX) !== false) {
                        $dataSite404[$dataKey] = $data[$dataKey];
                    }
                    
                    if(strpos($dataKey, self::DOMAIN_TABLE_PREFIX) !== false) {
                        $dataDomain[$dataKey] = $data[$dataKey];
                    }
                }
                
                $isValidName = false;
                // Checking if the Site name is existing on the site lists
                $siteName = $this->getRequest()->getPost('site_name');
                $siteData = $siteTable->getEntryByField('site_name', $siteName)->current();
                
                if (is_null($siteId))
                {
                    if (empty($siteData))
                    {
                        $isValidName = true;
                    }
                }
                else 
                {
                    if (!empty($siteData))
                    {
                        
                        if ($siteData->site_id == $siteId)
                        {
                            $isValidName = true;
                        }
                    }
                    else 
                    {
                        $isValidName = true;
                    }
                }
                
                if($isValidName) 
                {
                    $genSiteModule = !empty($request->getPost('gen_site_mod')) ? true : false;
                    
                    $cmsSiteSrv = $this->getServiceLocator()->get('MelisCmsSiteService');
                    $saveSiteResult = $cmsSiteSrv->saveSite($dataSite, $dataDomain, $dataSite404, $dataSiteLang, $siteId, $genSiteModule, $dataSite['site_name']);
                    
                    if ($saveSiteResult['success'])
                    {
                        if (is_null($siteId))
                        {
                            $textMessage = 'tr_meliscms_tool_site_add_success';
                        }
                        else 
                        {
                            $textMessage = 'tr_meliscms_tool_site_edit_success';
                        }
                        
                        $siteId = $saveSiteResult['site_id'];
                        // to solve the error on loading css and js
                        // regenerate the melis.modules.path cause the newly created path is not
                        // included in the file
                        $this->regenerateModulesPath();
                        $status = 1;
                    }
                    else 
                    {
                        if ($saveSiteResult['message'] == 'tr_meliscms_tool_site_no_platform_ids')
                        {
                            $textMessage = 'tr_meliscms_tool_site_error_prompt_add';
                            $errors['platformId'] = array(
                                'label' => $translator->translate('tr_meliscms_tool_platform_ids'),
                                'noPlatformIds' => $translator->translate('tr_meliscms_tool_site_no_platform_ids')
                            );
                        }
                        else 
                        {
                            $textMessage = $saveSiteResult['message'];
                        }
                    }
                    
                    unset($data);
                    unset($dataSite);
                    unset($dataSite404);
                    unset($dataDomain);
                }
                else 
                {
                    // if data already exists then add manually the foreign site id key
                    $textMessage = 'tr_meliscms_tool_site_error_prompt_add';
                    $errors = array(
                        'site_name' => array(
                            'siteAlreadyExists' => $translator->translate('tr_meliscms_tool_site_name_exists')
                        ),
                    );
                }
            }
            else 
            {
                if (is_null($siteId))
                {
                    $textMessage = 'tr_meliscms_tool_site_error_prompt_add';
                }
                else
                {
                    $textMessage = 'tr_meliscms_tool_site_edit_failed';
                }
                
                $errors = $siteForm->getMessages();
                $status = 0;
            }
            
            // insert labels and error messages in error array
            $melisMelisCoreConfig = $this->serviceLocator->get('MelisCoreConfig');
            $appConfigForm = $melisMelisCoreConfig->getItem('meliscms/tools/meliscms_tool_site/forms/'.$siteFormType);
            $appConfigForm = $appConfigForm['elements'];
            
            foreach ($errors as $keyError => $valueError)
            {
                foreach ($appConfigForm as $keyForm => $valueForm)
                {
                    if ($valueForm['spec']['name'] == $keyError && !empty($valueForm['spec']['options']['label']))
                    {
                        $errors[$keyError]['label'] = $valueForm['spec']['options']['label'];
                    }
                }
            }
        }
        
        $response = array(
            'success' => $status,
            'textTitle' => 'tr_meliscms_tool_site',
            'textMessage' => $textMessage,
            'errors' => $errors,
            'test' => $errors,
        );

        $this->getEventManager()->trigger('meliscms_site_save_end', $this, array_merge($response, array('typeCode' => $logTypeCode, 'itemId' => $siteId)));
        
        if ($siteId)
        {
            $response['siteId'] = $siteId;
        }
        
        return new JsonModel($response);
    }
634837
protected function saveCustomFields(): bool
    {
        //find the custom field module
        if (!$module = Modules::findFirstByName($this->getSource())) {
            return false;
        }

        //we need a new instane to avoid overwrite
        $reflector = new \ReflectionClass($this);
        $classNameWithNameSpace = $reflector->getNamespaceName() . '\\' . $reflector->getShortName() . 'CustomFields';

        //if all is good now lets get the custom fields and save them
        foreach ($this->customFields as $key => $value) {
            //create a new obj per itration to se can save new info
            $customModel = new $classNameWithNameSpace();

            //validate the custome field by it model
            if ($customField = CustomFields::findFirst(['conditions' => 'name = ?0 and modules_id = ?1', 'bind' => [$key, $module->id]])) {
                //throw new Exception("this custom field doesnt exist");

                $customModel->setCustomId($this->getId());
                $customModel->custom_fields_id = $customField->id;
                $customModel->value = $value;
                $customModel->created_at = date('Y-m-d H:i:s');

                if (!$customModel->save()) {
                    throw new Exception('Custome ' . $key . ' - ' . $this->customModel->getMessages()[0]);
                }
            }
        }

        //clean
        unset($this->customFields);

        return true;
    }
1061798
protected function saveEditor()
    {
        $this->controlAccessSaveEditor();

        $submitted = $this->getSubmitted();
        $result = $this->editor->save($submitted);

        if ($result === true) {
            $message = $this->text('File has been saved');
            $this->redirect("admin/tool/editor/{$submitted['module']['id']}", $message, 'success');
        }

        $this->redirect('', $this->text('An error occurred'), 'warning');
    }
413000
public function save($exclude_post = false)
    {
        if (count($this->_info) === 0) {
            return false;
        }

        // set defaults
        $defaults = $this->getDefaults();
        if (count($defaults) > 0) {
            foreach ($defaults as $k => $v) {
                if (!array_key_exists($k, $this->_info)) {
                    $this->_info[$k] = $v;
                }
            }
        }

        // separate regular post fields from meta
        $post = array();
        $meta = array();
        $post_fields = static::getCoreFieldKeys();
        $fields_and_attribs = static::getFields();
        $meta_fields = array_keys($fields_and_attribs);

        foreach ($this->_info as $k => $v) {
            if (in_array($k, $post_fields)) {
                $post[$k] = $v;
            } elseif (in_array($k, $meta_fields)) {
                $meta[$k] = $v;
            }
        }

        // save post
        $is_update = array_key_exists(self::ID, $post);
        if (!$exclude_post) {
            if ($is_update) {
                wp_update_post($post);
            } else {
                // Pass true as the second param to wp_insert_post
                // so that WP won't silently fail if we hit an error
                $id = wp_insert_post($post, true);
                if (!is_int($id)) {
                    $this->last_error = $id;
                    return false;
                }

                $this->_info[self::ID] = $id;
            }

            // Hack to fix ampersand saving in post titles
            // TODO See if there is a better way to do this
            if ($this->_info[self::ID] && array_key_exists('post_title', $post) && preg_match('/[&\']{1,}/', $post['post_title'])) {
                global $wpdb;
                $prepared_sql = $wpdb->prepare(
                    "UPDATE {$wpdb->posts} SET post_title=%s WHERE ID=%d",
                    $post['post_title'],
                    $this->_info[self::ID]
                );
                $wpdb->query($prepared_sql);
            }
        }

        // delete old meta
        if ($is_update) {
            $old_meta = get_post_meta($this->_info[self::ID]);
            if (Arr::iterable($old_meta)) {
                foreach ($old_meta as $old_meta_k => $old_meta_vals) {
                    if (preg_match('/^_/', $old_meta_k)) {
                        continue;
                    }

                    delete_post_meta($this->_info[self::ID], $old_meta_k);
                }
            }
        }

        // save meta
        if (count($meta) > 0) {
            foreach ($meta as $k => $v) {
                if (preg_match('/link/', $fields_and_attribs[$k]['type'])) {
                    $v = urldecode($v);
                }
                if ($is_update) {
                    update_post_meta($this->_info[self::ID], $k, $v);
                } else {
                    add_post_meta($this->_info[self::ID], $k, $v);
                }
            }
        }

        // save terms
        if (Arr::iterable($this->_terms) > 0) {
            foreach ($this->_terms as $taxonomy_key => $term_ids) {
                if (!Arr::iterable($term_ids)) {
                    continue;
                }

                foreach ($term_ids as $n => $term_id) {
                    // Did a name get passed that's not a term_id?
                    // Try getting the term_id, or saving a new term and using that term_id
                    $convert_term_name_to_term_id = (
                        is_string($term_id)
                        && !is_numeric($term_id)
                        && $taxonomy_key !== 'post_tag'
                    );
                    if ($convert_term_name_to_term_id) {
                        $term = get_term_by('name', $term_id, $taxonomy_key);
                        if (!is_object($term)) {
                            $term = wp_insert_term($term_id, $taxonomy_key);
                        }
                        $term_id = (object) $term;
                    }

                    // The terms might come in as an ID or a whole term object
                    // This makes sure the wp_set_post_terms call only gets term IDs, not objects
                    if (is_object($term_id)) {
                        $term_ids[$n] = $term_id->term_id;
                    }
                }
                
                wp_set_post_terms($this->_info[self::ID], $term_ids, $taxonomy_key);
            }
        }

        return $this->_info[self::ID];
    }