*/ class BlogPostFilter extends DataExtension { /** * Augment queries so that we don't fetch unpublished articles. * * @param SQLSelect $query * @param DataQuery $query */ public function augmentSQL(SQLSelect $query, DataQuery $dataQuery = null) { if (Controller::has_curr() && Controller::curr() instanceof LeftAndMain) { return; } if (Versioned::get_stage() === Versioned::LIVE || ( Versioned::get_draft_site_secured() && !Permission::check('VIEW_DRAFT_CONTENT') ) ) { $query->addWhere(sprintf( '"PublishDate" < \'%s\'', Convert::raw2sql(DBDatetime::now()) )); } } /** * {@inheritDoc} * * This is a fix so that when we try to fetch subclasses of BlogPost, lazy loading includes the * BlogPost table in its query. Leaving this table out means the default sort order column * PublishDate causes an error. * * @see https://github.com/silverstripe/silverstripe-framework/issues/1682 * * @param SQLSelect $query * @param DataQuery $dataQuery * @param DataObject $dataObject */ public function augmentLoadLazyFields(SQLSelect &$query, DataQuery &$dataQuery = null, $dataObject) { $blogPostTable = DataObject::getSchema()->tableName(BlogPost::class); $dataQuery->innerJoin( $blogPostTable, '"SiteTree"."ID" = "' . $blogPostTable . '"."ID"' ); } }