本文整理汇总了PHP中blogPostModel::updateItem方法的典型用法代码示例。如果您正苦于以下问题:PHP blogPostModel::updateItem方法的具体用法?PHP blogPostModel::updateItem怎么用?PHP blogPostModel::updateItem使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类blogPostModel
的用法示例。
在下文中一共展示了blogPostModel::updateItem方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: execute
public function execute()
{
ob_start();
$app = $this->getApp();
$app_settings_model = new waAppSettingsModel();
$app_settings_model->set($app, 'cron_schedule', time());
waFiles::create($this->getConfig()->getPath('log') . '/' . $app . '/');
$log_file = "{$app}/cron.txt";
$post_model = new blogPostModel();
$params = array('datetime' => date("Y-m-d H:i:s"), 'status' => blogPostModel::STATUS_SCHEDULED);
$posts_schedule = $post_model->select("id,blog_id,contact_id,status,datetime")->where('datetime <= s:datetime AND status=s:status', $params)->fetchAll();
if ($posts_schedule) {
foreach ($posts_schedule as $post) {
try {
waLog::log("Attempt publishing post with id [{$post['id']}]", $log_file);
$data = array("status" => blogPostModel::STATUS_PUBLISHED);
waLog::log($post_model->updateItem($post['id'], $data, $post) ? "success" : "fail", $log_file);
} catch (Exception $ex) {
waLog::log($ex->getMessage(), $log_file);
waLog::log($ex->getTraceAsString(), $log_file);
}
}
}
$action = __FUNCTION__;
/**
* @event cron_action
* @param string $action
* @return void
*/
wa()->event('cron_action', $action);
if ($log = ob_get_clean()) {
waLog::log($log, $log_file);
}
}
示例2: execute
public function execute()
{
if ($target_blog = max(0, $this->getRequest()->post('blog', 0, waRequest::TYPE_INT))) {
$blog_model = new blogBlogModel();
if ($blog = $blog_model->getById($target_blog)) {
if ($ids = $this->getRequest()->post('id', null, waRequest::TYPE_ARRAY_INT)) {
$post_model = new blogPostModel();
$comment_model = new blogCommentModel();
$this->response['moved'] = array();
foreach ($ids as $id) {
try {
//rights will checked for each record separately
$post_model->updateItem($id, array('blog_id' => $target_blog));
$comment_model->updateByField('post_id', $id, array('blog_id' => $target_blog));
$this->response['moved'][$id] = $id;
} catch (Exception $ex) {
if (!isset($this->response['error'])) {
$this->response['error'] = array();
}
$this->response['error'][$id] = $ex->getMessage();
}
}
$this->response['style'] = $blog['color'];
$blog_model->recalculate();
}
} else {
}
}
}
示例3: execute
public function execute()
{
$id = $this->get('id', true);
$post_model = new blogPostModel();
$post = $post_model->getById($id);
if (!$post) {
throw new waAPIException('invalid_param', 'Post not found', 404);
}
//check rights
if (blogHelper::checkRights($post['blog_id']) < blogRightConfig::RIGHT_FULL && $post['contact_id'] != wa()->getUser()->getId()) {
throw new waAPIException('access_denied', 403);
}
$data = array_merge($post, waRequest::post());
$blog_model = new blogBlogModel();
$blogs = $blog_model->getAvailable();
if (!isset($blogs[$data['blog_id']])) {
throw new waAPIException('invalid_param', 'Blog not found', 404);
}
$blog = $blogs[$data['blog_id']];
$data['blog_status'] = $blog['status'];
$data['datetime'] = $this->formateDatetime($data['datetime']);
$messages = $post_model->validate($data, array('transliterate' => true));
if ($messages) {
throw new waAPIException('invalid_param', 'Validate messages: ' . implode("\n", $messages), 404);
}
$post_model->updateItem($data['id'], $data);
$_GET['id'] = $id;
$method = new blogPostGetInfoMethod();
$this->response = $method->getResponse(true);
}
示例4: execute
public function execute()
{
$data = waRequest::post();
// check required params
$this->post('blog_id', true);
$this->post('title', true);
$blog_model = new blogBlogModel();
$blogs = $blog_model->getAvailable();
if (!isset($blogs[$data['blog_id']])) {
throw new waAPIException('invalid_param', 'Blog not found', 404);
}
$blog = $blogs[$data['blog_id']];
if ($blog['rights'] < blogRightConfig::RIGHT_READ_WRITE) {
throw new waAPIException('access_denied', 403);
}
$data = array_merge($data, array('blog_status' => $blog['status'], 'url' => '', 'text' => '', 'status' => blogPostModel::STATUS_PUBLISHED));
$post_model = new blogPostModel();
$options = array();
if (waRequest::post('transliterate', null)) {
$options['transliterate'] = true;
}
$messages = $post_model->validate($data, array('transliterate' => true));
if ($messages) {
throw new waAPIException('invalid_param', 'Validate messages: ' . implode("\n", $messages), 404);
}
$id = $post_model->updateItem(null, $data);
$_GET['id'] = $id;
$method = new blogPostGetInfoMethod();
$this->response = $method->getResponse(true);
}
示例5: run
public function run($params = NULL)
{
$app = $this->getApp();
$app_settings_model = new waAppSettingsModel();
$app_settings_model->set($app, 'last_schedule_cron_time', time());
waFiles::create($this->getConfig()->getPath('log') . '/' . $app . '/');
$log_file = "{$app}/schedule.txt";
$post_model = new blogPostModel();
$params = array('datetime' => date("Y-m-d H:i:s"), 'status' => blogPostModel::STATUS_SCHEDULED);
$posts_schedule = $post_model->select("id, blog_id, contact_id, status, datetime")->where('datetime <= s:datetime AND status=s:status', $params)->fetchAll();
if ($posts_schedule) {
foreach ($posts_schedule as $post) {
try {
waLog::log("Attempt publishing post with id [{$post['id']}]", $log_file);
$data = array("status" => blogPostModel::STATUS_PUBLISHED, "datetime" => date("Y-m-d H:i:s"));
$r = $post_model->updateItem($post['id'], $data, $post);
waLog::log($r ? "success" : "fail", $log_file);
} catch (Exception $ex) {
waLog::log($ex->getMessage(), $log_file);
waLog::log($ex->getTraceAsString(), $log_file);
}
}
}
}
示例6: insertPost
protected function insertPost($post)
{
static $post_model;
if (!$post_model) {
$post_model = new blogPostModel();
}
if (empty($post['contact_id'])) {
$post['contact_id'] = $this->settings['contact'];
}
$method = __METHOD__;
$this->log(var_export(compact('method', 'post'), true));
$post['blog_id'] = $this->settings['blog'];
$post['blog_status'] = $this->settings['blog_status'];
$post['text'] = $this->userReplace($post['text']);
$post_model->ping();
switch ($field = $this->settings['mode']) {
case 'title':
if ($p = $post_model->getByField(array($field => $post[$field], 'blog_id' => $post['blog_id']))) {
$this->log("Post with timestamp [{$post['timestamp']}] skipped because there was a duplicate (id={$p['id']})", self::LOG_NOTICE);
$this->log("Post raw data " . var_export($post, true), self::LOG_DEBUG);
return false;
}
break;
}
if ($post['blog_status'] == blogBlogModel::STATUS_PUBLIC) {
$post['url'] = $post_model->genUniqueUrl(empty($post['url']) ? $post['title'] : $post['url']);
} elseif (!empty($post['url'])) {
$post['url'] = $post_model->genUniqueUrl($post['url']);
} else {
$post['url'] = '';
}
$post['id'] = $post_model->updateItem(null, $post);
return $post;
}
示例7: save
private function save($post)
{
$options = array();
if (waRequest::post('transliterate', null)) {
$options['transliterate'] = true;
}
$this->validate_messages = $this->post_model->validate($post, $options);
if ($this->validate_messages) {
$this->errors = $this->validate_messages;
} else {
$post['text_before_cut'] = null;
$post['cut_link_label'] = null;
$template = '<!--[\\s]*?more[\\s]*?(text[\\s]*?=[\\s]*?[\'"]([\\s\\S]*?)[\'"])*[\\s]*?-->';
$descriptor = preg_split("/{$template}/", $post['text'], 2, PREG_SPLIT_DELIM_CAPTURE);
if ($descriptor) {
if (count($descriptor) == 2) {
$post['text_before_cut'] = blogPost::closeTags($descriptor[0]);
} elseif (count($descriptor) > 2) {
$post['text_before_cut'] = blogPost::closeTags($descriptor[0]);
if (isset($descriptor[2])) {
$post['cut_link_label'] = $descriptor[2];
}
}
}
if ($post['id']) {
$prev_post = $this->post_model->getFieldsById($post['id'], 'status');
if ($prev_post['status'] != blogPostModel::STATUS_PUBLISHED && $post['status'] == blogPostModel::STATUS_PUBLISHED) {
$this->inline = false;
}
$this->post_model->updateItem($post['id'], $post);
if ($prev_post['status'] != blogPostModel::STATUS_PUBLISHED && $post['status'] == blogPostModel::STATUS_PUBLISHED) {
$this->log('post_publish', 1);
} else {
$this->log('post_edit', 1);
}
} else {
$post['id'] = $this->post_model->updateItem(null, $post);
$this->log('post_publish', 1);
}
$this->saveParams($post['id']);
$this->clearViewCache($post['id'], $post['url']);
if (!$this->inline) {
if ($post['status'] != blogPostModel::STATUS_PUBLISHED) {
$params = array('module' => 'post', 'action' => 'edit', 'id' => $post['id']);
} elseif ($post['blog_status'] == blogBlogModel::STATUS_PUBLIC) {
$params = array('blog' => $post['blog_id']);
} else {
$params = array('module' => 'post', 'id' => $post['id']);
}
$this->response['redirect'] = $this->getRedirectUrl($params);
} else {
$this->response['formatted_datetime'] = waDateTime::format('humandatetime', $post['datetime']);
$this->response['id'] = $post['id'];
$this->response['url'] = $post['url'];
if ($post['status'] != blogPostModel::STATUS_PUBLISHED) {
$options = array('contact_id' => $post['contact_id'], 'blog_id' => $post['blog_id'], 'post_id' => $post['id'], 'user_id' => wa()->getUser()->getId());
$preview_hash = blogPostModel::getPreviewHash($options);
$this->response['preview_hash'] = base64_encode($preview_hash . $options['user_id']);
$this->response['debug'] = $options;
}
}
}
}