silverstripe-blog/code/compat/pages/BlogEntry.php

113 lines
2.3 KiB
PHP
Raw Normal View History

2015-02-08 08:03:55 +01:00
<?php
/**
* @deprecated since version 2.0
2015-05-09 16:33:12 +02:00
*
* @property int $ParentID
* @property string $Date
* @property string $PublishDate
* @property string $Tags
2015-02-08 08:03:55 +01:00
*/
class BlogEntry extends BlogPost implements MigratableObject {
2015-05-09 16:33:12 +02:00
/**
* @var string
*/
2015-02-08 08:03:55 +01:00
private static $hide_ancestor = 'BlogEntry';
2015-05-09 16:33:12 +02:00
/**
* @var array
*/
2015-02-08 08:03:55 +01:00
private static $db = array(
2015-05-09 16:33:12 +02:00
'Date' => 'SS_Datetime',
'Author' => 'Text',
'Tags' => 'Text',
2015-02-08 08:03:55 +01:00
);
/**
2015-05-09 16:33:12 +02:00
* {@inheritdoc}
2015-02-08 08:03:55 +01:00
*/
public function canCreate($member = null) {
return false;
}
2015-05-09 16:33:12 +02:00
/**
* {@inheritdoc}
*/
2015-02-08 08:03:55 +01:00
public function up() {
//Migrate comma separated tags into BlogTag objects.
2015-02-08 08:03:55 +01:00
foreach($this->TagNames() as $tag) {
2015-06-29 09:17:53 +02:00
$existingTag = BlogTag::get()->filter(array('Title' => $tag, 'BlogID' => $this->ParentID));
if($existingTag->count()) {
//if tag already exists we will simply add it to this post.
$tagObject = $existingTag->First();
} else {
//if the tag is now we create it and add it to this post.
$tagObject = new BlogTag();
$tagObject->Title = $tag;
$tagObject->BlogID = $this->ParentID;
$tagObject->write();
2015-05-09 16:33:12 +02:00
}
2015-02-08 08:03:55 +01:00
if($tagObject){
$this->Tags()->add($tagObject);
}
2015-02-08 08:03:55 +01:00
}
//Store if the original entity was published or not (draft)
$published = $this->IsPublished();
2015-05-26 02:36:20 +02:00
// If a user has subclassed BlogEntry, it should not be turned into a BlogPost.
2015-05-26 02:26:22 +02:00
if($this->ClassName === 'BlogEntry') {
$this->ClassName = 'BlogPost';
2015-05-26 02:36:20 +02:00
$this->RecordClassName = 'BlogPost';
2015-05-26 02:26:22 +02:00
}
//Migrate these key data attributes
$this->PublishDate = $this->Date;
$this->AuthorNames = $this->Author;
$this->InheritSideBar = true;
2015-05-26 02:26:22 +02:00
//Write and additionally publish the item if it was published before.
2015-05-25 03:39:51 +02:00
$this->write();
if($published){
$this->publish('Stage','Live');
$message = "PUBLISHED: ";
} else {
$message = "DRAFT: ";
}
return $message . $this->Title;
2015-02-08 08:03:55 +01:00
}
2015-05-09 16:33:12 +02:00
/**
* Safely split and parse all distinct tags assigned to this BlogEntry.
*
* @deprecated since version 2.0
*
* @return array
*/
public function TagNames() {
$tags = preg_split('/\s*,\s*/', trim($this->Tags));
$results = array();
foreach($tags as $tag) {
if($tag) $results[mb_strtolower($tag)] = $tag;
}
return $results;
}
2015-02-08 08:03:55 +01:00
}
/**
* @deprecated since version 2.0
*/
class BlogEntry_Controller extends BlogPost_Controller {
2015-05-09 16:33:12 +02:00
2015-02-08 08:03:55 +01:00
}