Pommo_Api::configUpdate PHP Method

configUpdate() static public method

$input must be an array as key:value ([config_name] => config_value)
static public configUpdate ( $input, $force = FALSE )
    static function configUpdate($input, $force = FALSE)
    {
        $dbo = Pommo::$_dbo;
        if (!is_array($input)) {
            Pommo::kill('Bad input passed to updateConfig', TRUE);
        }
        // if this is password, skip if empty
        if (isset($input['admin_password']) && empty($input['admin_password'])) {
            unset($input['admin_password']);
        }
        // get eligible config rows/options to change
        $force = $force ? null : 'on';
        $query = "\n            SELECT config_name\n            FROM " . $dbo->table['config'] . "\n            WHERE config_name IN(%q)\n            [AND user_change='%S']";
        $query = $dbo->prepare($query, array(array_keys($input), $force));
        // update rows/options
        $when = '';
        // multi-row update in a single query syntax
        while ($row = $dbo->getRows($query)) {
            $when .= $dbo->prepare("WHEN '%s' THEN '%s'", array($row['config_name'], $input[$row['config_name']])) . ' ';
            // limits multi-row update query to specific rows
            // (vs updating entire table)
            $where[] = $row['config_name'];
        }
        $query = "\n            UPDATE " . $dbo->table['config'] . "\n            SET config_value =\n                CASE config_name " . $when . " ELSE config_value END\n            [WHERE config_name IN(%Q)]";
        $query = $dbo->prepare($query, array($where));
        if (!$dbo->query($query)) {
            Pommo::kill('Error updating config');
        }
        return true;
    }

Usage Example

Example #1
0
        $messages['confirm']['sub'] = $_POST['confirm_sub'];
        $messages['confirm']['msg'] = $_POST['confirm_msg'];
        $messages['activate'] = array();
        $messages['activate']['sub'] = $_POST['activate_sub'];
        $messages['activate']['msg'] = $_POST['activate_msg'];
        $messages['update'] = array();
        $messages['update']['sub'] = $_POST['update_sub'];
        $messages['update']['msg'] = $_POST['update_msg'];
        $notices = array();
        $notices['email'] = $_POST['notify_email'];
        $notices['subject'] = $_POST['notify_subject'];
        $notices['subscribe'] = $_POST['notify_subscribe'];
        $notices['unsubscribe'] = $_POST['notify_unsubscribe'];
        $notices['update'] = $_POST['notify_update'];
        $notices['pending'] = $_POST['notify_pending'];
        $input = array('messages' => serialize($messages), 'notices' => serialize($notices));
        Pommo_Api::configUpdate($input, TRUE);
        $json->success(Pommo::_T('Configuration Updated.'));
    } else {
        // __ FORM NOT VALID
        $json->add('fieldErrors', $smarty->getInvalidFields('messages'));
        $json->fail(Pommo::_T('Please review and correct errors with your submission.'));
    }
}
$smarty->assign('t_subscribe', Pommo::_T('Subscription'));
$smarty->assign('t_unsubscribe', Pommo::_T('Unsubscription'));
$smarty->assign('t_pending', Pommo::_T('Pending'));
$smarty->assign('t_update', Pommo::_T('Update'));
$smarty->assign($_POST);
$smarty->display('admin/setup/config/messages.tpl');
Pommo::kill();
All Usage Examples Of Pommo_Api::configUpdate