Hooks::update_option ( $meta_key,  $newvalue )

Update (add if doesn’t exist) an option to options_meta

Source file: app/src/Hooks.php

View source


Used by


Source

    public function update_option($meta_key, $newvalue)
    {
        $oldvalue = $this->get_option($meta_key);

        // If the new and old values are the same, no need to update.
        if ($newvalue === $oldvalue) {
            return false;
        }

        if (null === $oldvalue) {
            $this->add_option($meta_key, $newvalue);
            return true;
        }

        $_newvalue = $this->maybe_serialize($newvalue);

        etsis_cache_delete($meta_key, 'option');
        
        $this->do_action('update_option', $meta_key, $oldvalue, $newvalue);
        try {            
            $key = $this->app->db->options_meta();
            $key->meta_value = $_newvalue;
            $key->where('meta_key = ?', $meta_key)->update();

            if (count($key) > 0) {
                $this->app->db->option[$meta_key] = $newvalue;
            }
        } catch (NotFoundException $e) {
            Cascade::getLogger('error')->error(sprintf('SQLSTATE[%s]: Error: %s', $e->getCode(), $e->getMessage()));
            _etsis_flash()->error(_etsis_flash()->notice(409));
        } catch (ORMException $e) {
            Cascade::getLogger('error')->error(sprintf('SQLSTATE[%s]: Error: %s', $e->getCode(), $e->getMessage()));
            _etsis_flash()->error(_etsis_flash()->notice(409));
        } catch (Exception $e) {
            Cascade::getLogger('error')->error(sprintf('SQLSTATE[%s]: Error: %s', $e->getCode(), $e->getMessage()));
            _etsis_flash()->error(_etsis_flash()->notice(409));
        }
    }


User Contributed Notes

You must log in before being able to contribute a note.