Skip to content

Commit 4e1015f

Browse files
committed
Fixes for include in recent after code review
1 parent c4a5240 commit 4e1015f

File tree

8 files changed

+36
-15
lines changed

8 files changed

+36
-15
lines changed

Block/Index.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,16 @@ protected function _preparePostCollection()
4848
\Magefan\Blog\Helper\Config::XML_PATH_HOMEPAGE_DISPLAY_MODE,
4949
ScopeInterface::SCOPE_STORE
5050
);
51+
5152
/* If featured posts enabled */
5253
if ($displayMode == 1) {
5354
$postIds = $this->_scopeConfig->getValue(
5455
\Magefan\Blog\Helper\Config::XML_PATH_HOMEPAGE_FEATURED_POST_IDS,
5556
ScopeInterface::SCOPE_STORE
5657
);
5758
$this->_postCollection->addPostsFilter($postIds);
59+
} else {
60+
$this->_postCollection->addRecentFilter();
5861
}
5962
}
6063

Block/Sidebar/Recent.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,17 @@ public function _construct()
3434
return parent::_construct();
3535
}
3636

37+
/*
38+
* Prepare posts collection
39+
*
40+
* @return void
41+
*/
42+
protected function _preparePostCollection()
43+
{
44+
parent::_preparePostCollection();
45+
$this->_postCollection->addRecentFilter();
46+
}
47+
3748
/**
3849
* Retrieve block identities
3950
* @return array

Block/Widget/Recent.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ protected function _preparePostCollection()
9191

9292
parent::_preparePostCollection();
9393

94+
$this->_postCollection->addRecentFilter();
9495
if ($category = $this->getCategory()) {
9596
$this->_postCollection->addCategoryFilter($category);
9697
}

Model/Post.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -844,6 +844,7 @@ public function getSecret()
844844
);
845845
$this->save();
846846
}
847+
847848
return $this->getData('secret');
848849
}
849850
}

Model/PostManagement.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ public function getList($type, $term, $storeId, $page, $limit)
8484
$collection->addTagFilter($term);
8585
break;
8686
}
87+
8788
$posts = [];
8889
foreach ($collection as $item) {
8990
$item->initDinamicData();

Model/ResourceModel/Post/Collection.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,10 @@ public function addStoreFilter($store, $withAdmin = true)
131131
return $this;
132132
}
133133

134+
/**
135+
* Add "include in recent" filter to collection
136+
* @return $this
137+
*/
134138
public function addRecentFilter()
135139
{
136140
return $this->addFieldToFilter('include_in_recent', 1);

Setup/UpgradeSchema.php

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -470,36 +470,36 @@ public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $con
470470
$setup->getIdxName($setup->getTable('magefan_blog_category'), ['include_in_menu']),
471471
['include_in_menu']
472472
);
473-
if (version_compare($version, '2.6.3') < 0)
474-
{
475-
/* Add include in recent posts into post table */
473+
}
474+
475+
if (version_compare($version, '2.6.3') < 0) {
476+
/* Add display mode field into category table */
476477
$connection->addColumn(
477-
$setup->getTable('magefan_blog_post'),
478-
'include_in_recent',
478+
$setup->getTable('magefan_blog_category'),
479+
'display_mode',
479480
[
480481
'type' => \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT,
481482
null,
482483
'nullable' => false,
483-
'default' => '1',
484-
'comment' => 'Include in Recent Posts',
484+
'default' => '0',
485+
'comment' => 'Display Mode',
485486
'after' => 'is_active'
486487
]
487488
);
488489
}
489490

490-
}
491491

492-
if (version_compare($version, '2.6.3') < 0) {
493-
/* Add display mode field into category table */
492+
if (version_compare($version, '2.6.3.1') < 0) {
493+
/* Add include in recent posts into post table */
494494
$connection->addColumn(
495-
$setup->getTable('magefan_blog_category'),
496-
'display_mode',
495+
$setup->getTable('magefan_blog_post'),
496+
'include_in_recent',
497497
[
498498
'type' => \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT,
499499
null,
500500
'nullable' => false,
501-
'default' => '0',
502-
'comment' => 'Display Mode',
501+
'default' => '1',
502+
'comment' => 'Include in Recent Posts',
503503
'after' => 'is_active'
504504
]
505505
);

etc/module.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*/
99
-->
1010
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
11-
<module name="Magefan_Blog" setup_version="2.6.3">
11+
<module name="Magefan_Blog" setup_version="2.6.3.1">
1212
<sequence>
1313
<module name="Magento_Cms"/>
1414
<module name="Magento_Catalog"/>

0 commit comments

Comments
 (0)