Skip to content

Commit

Permalink
Fixed bugs with publish date.
Browse files Browse the repository at this point in the history
  • Loading branch information
Stardog committed Jan 29, 2019
1 parent e17ed6e commit 1637680
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 28 deletions.
19 changes: 3 additions & 16 deletions Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
use Canopy\Response;
use Canopy\Server;

require_once PHPWS_SOURCE_DIR . 'src/Module.php';

class Module extends \Canopy\Module implements \Canopy\SettingDefaults
{

Expand All @@ -29,18 +27,6 @@ public function __construct()
$this->setProperName('Stories');
spl_autoload_register('\stories\Module::autoloader', true, true);
}

public function needsUpdate() {
if (empty($this->file_version)) {
$this->loadFileVersion();
}
return version_compare($this->file_version, $this->version, '>');
}

public function loadFileVersion() {
include PHPWS_SOURCE_DIR . 'mod/' . $this->title . '/boost/boost.php';
$this->file_version = $version;
}

public function getSettingDefaults()
{
Expand Down Expand Up @@ -110,11 +96,12 @@ public function runTime(Request $request)

private function frontPage(Request $request)
{
if (!$request->isGet() || $request->getUrl() != '/') {
if (!empty($request->getModule())) {
return;
}
if ($this->needsUpdate()) {
\Layout::add('<div class="alert alert-warning">Stories needs updating.</div>', 'stories', 'stories', true);
\Layout::add('<div class="alert alert-warning">Stories needs updating.</div>',
'stories', 'stories', true);
return;
}
$featureView = new \stories\View\FeatureView;
Expand Down
2 changes: 1 addition & 1 deletion boost/boost.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* MA 02110-1301 USA
*/
$proper_name = 'Stories';
$version = '1.6.0';
$version = '1.6.1';
$register = false;
$unregister = false;
$import_sql = false;
Expand Down
2 changes: 1 addition & 1 deletion boost/dependency.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<module>
<title>core</title>
<properName>Canopy Core</properName>
<version>3.0.4</version>
<version>3.0.5</version>
<url>http://github.com/AppStateESS/canopy/</url>
</module>
</dependency>
8 changes: 8 additions & 0 deletions boost/update.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ public function run()
$this->update('1.5.8');
case $this->compare('1.6.0'):
$this->update('1.6.0');
case $this->compare('1.6.1'):
$this->update('1.6.1');
}
return $this->content;
}
Expand Down Expand Up @@ -343,6 +345,12 @@ private function v1_6_0()
$changes[] = 'Fixed permanent link.';
$this->addContent('1.6.0', $changes);
}

private function v1_6_1()
{
$changes[] = 'Fixed bugs with publish date.';
$this->addContent('1.6.1', $changes);
}

private function addContent($version, array $changes)
{
Expand Down
7 changes: 7 additions & 0 deletions class/Factory/EntryFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,13 @@ private function patchEntry(Resource $entry, $param, $value)
$publishFactory->publishEntry($entry->id,
$entry->publishDate);
}
$entry->published = $value;
break;

case 'publishDate':
$publishFactory->updatePublishDateByEntryId($entry->id, $value);
$entry->publishDate = $value;
break;

default:
$entry->$param = $value;
Expand Down
31 changes: 27 additions & 4 deletions class/Factory/PublishFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,29 @@ public function publishEntry(int $entryId, int $publishDate)
}
}

public function publishShare(int $shareId, int $publishDate, int $showInList=1)
/**
* Changes the publish date of an entry only. Unpublished entries are
* ignored.
* @param int $entryId
* @param type $publishDate
* @return type
*/
public function updatePublishDateByEntryId(int $entryId, $publishDate)
{
$publishId = $this->getPublishIdByEntryId($entryId);
if (empty($publishId)) {
return;
}
$db = Database::getDB();
$tbl = $db->addTable('storiespublish');
$tbl->addValue('entryId', $entryId);
$tbl->addValue('publishDate', $publishDate);
$tbl->addFieldConditional('entryId', $entryId);
$db->update();
}

public function publishShare(int $shareId, int $publishDate,
int $showInList = 1)
{
$db = Database::getDB();
$tbl = $db->addTable('storiespublish');
Expand Down Expand Up @@ -162,15 +184,15 @@ private function deleteTrackHosts(int $entryId)
$tbl->addFieldConditional('entryId', $entryId);
return $db->delete();
}

public function patchByEntry($entryId, $varname, $value)
{
$publish = $this->loadByEntryId($entryId);
$publish->$varname = $value;
$this->saveResource($publish);
return true;
}

public function patchByShare($shareId, $varname, $value)
{
$publish = $this->loadByShareId($shareId);
Expand All @@ -193,6 +215,7 @@ public function listing(array $options = null)
$tbl = $db->addTable('storiespublish');
$tbl->addOrderBy('publishDate', 'desc');
$tbl->addFieldConditional('showInList', 1);
$tbl->addFieldConditional('publishDate', time(), '<=');

/**
* To get an accurate test to see if there are more entries for
Expand Down Expand Up @@ -298,7 +321,7 @@ public function loadByShareId($shareId)
$publish = $this->build($row);
return $publish;
}

public function loadByEntryId($entryId)
{
$db = Database::getDB();
Expand Down
7 changes: 3 additions & 4 deletions javascript/EntryList/EntryList.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -194,10 +194,9 @@ export default class EntryList extends Component {
}, this.load)
}

setPublishDate(e) {
let entry = this.currentEntry()
const value = e.target.value
entry.publishDate = moment(value).unix()
setPublishDate(publishDate) {
const entry = this.currentEntry()
entry.publishDate = publishDate.getTime() / 1000
this.updateEntry(entry)
}

Expand Down
2 changes: 1 addition & 1 deletion npm-shrinkwrap.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "stories",
"version": "1.6.0",
"version": "1.6.1",
"description": "Canopy blog module",
"repository": {
"type": "git",
Expand Down

0 comments on commit 1637680

Please sign in to comment.