mirror of
https://github.com/Oreolek/oreolek.ru.git
synced 2024-05-16 16:08:22 +03:00
posts now have update times
This commit is contained in:
parent
1726f717b4
commit
02f69f97ad
|
@ -69,7 +69,7 @@ class Controller_Post extends Controller_Layout {
|
|||
}
|
||||
}
|
||||
$cache = Cache::instance('apcu');
|
||||
$latest_change = $post->creation_date();
|
||||
$latest_change = $post->updated_at;
|
||||
$this->template = new View_Post_View;
|
||||
$this->template->is_admin = $is_admin;
|
||||
$this->template->id = $id;
|
||||
|
@ -155,7 +155,7 @@ class Controller_Post extends Controller_Layout {
|
|||
$body = $cache->get('read_posts_'.$current_page);
|
||||
if (!empty($body))
|
||||
{
|
||||
$latest_change = Model_Post::get_latest_date();
|
||||
$latest_change = Model_Post::get_latest_change();
|
||||
if ($cache->get('latest_post') === $latest_change)
|
||||
{
|
||||
$this->response->body($body);
|
||||
|
@ -310,6 +310,7 @@ class Controller_Post extends Controller_Layout {
|
|||
$this->auto_render = FALSE;
|
||||
if ($this->request->post('mode') === 'save')
|
||||
{
|
||||
$post->updated_at = date('c');
|
||||
$post->save();
|
||||
$cache = Cache::instance('apcu');
|
||||
$cache->set('post_'.$post->id, NULL);
|
||||
|
@ -334,6 +335,7 @@ class Controller_Post extends Controller_Layout {
|
|||
{
|
||||
if ($mode === 'edit')
|
||||
{
|
||||
$post->updated_at = date('c');
|
||||
$post->save();
|
||||
$cache = Cache::instance('apcu');
|
||||
$cache->set('post_'.$post->id, NULL);
|
||||
|
|
|
@ -25,14 +25,14 @@ class Model_Post extends ORM {
|
|||
* @return array validation rules
|
||||
**/
|
||||
public function rules()
|
||||
{
|
||||
return array(
|
||||
{
|
||||
return array(
|
||||
'name' => array(
|
||||
array('not_empty'),
|
||||
array('not_empty'),
|
||||
),
|
||||
'content' => array(
|
||||
array('not_empty'),
|
||||
array('min_length', array(':value', 4)),
|
||||
array('not_empty'),
|
||||
array('min_length', array(':value', 4)),
|
||||
),
|
||||
'draft' => array(
|
||||
array('numeric')
|
||||
|
@ -40,8 +40,8 @@ class Model_Post extends ORM {
|
|||
'posted_at' => array(
|
||||
array('date')
|
||||
),
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
protected $_has_many = array(
|
||||
'comments' => array(
|
||||
|
@ -63,7 +63,8 @@ class Model_Post extends ORM {
|
|||
'content' => 'Текст записи',
|
||||
'is_draft' => 'Черновик',
|
||||
'posted_at' => 'Дата',
|
||||
'password' => 'Пароль для расшифровки'
|
||||
'password' => 'Пароль для расшифровки',
|
||||
'updated_at' => 'Дата изменения',
|
||||
);
|
||||
|
||||
/**
|
||||
|
@ -83,6 +84,12 @@ class Model_Post extends ORM {
|
|||
$query = DB::select(array(DB::expr('MAX(`posted_at`)'), 'max_date'))->from('posts');
|
||||
return $query->execute()->get('max_date');
|
||||
}
|
||||
|
||||
public static function get_latest_change()
|
||||
{
|
||||
$query = DB::select(array(DB::expr('MAX(`updated_at`)'), 'max_date'))->from('posts');
|
||||
return $query->execute()->get('max_date');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns array of ids and posted_at timestamps.
|
||||
|
|
|
@ -10,7 +10,7 @@ CREATE TABLE `posts` (
|
|||
`content` longtext NOT NULL,
|
||||
`is_draft` int(1) NOT NULL DEFAULT 0,
|
||||
`posted_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
`is_approved` int(1) unsigned NOT NULL DEFAULT '0',
|
||||
`updated_at` timestamp NOT NULL ON UPDATE CURRENT_TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
`password` varchar(50) NULL,
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||
|
|
Loading…
Reference in a new issue