@@ -19,53 +19,53 @@ |
||
| 19 | 19 | */ |
| 20 | 20 | class EventHolderController extends DatedUpdateHolderController |
| 21 | 21 | { |
| 22 | - public function getUpdateName() |
|
| 23 | - { |
|
| 24 | - $params = $this->parseParams(); |
|
| 25 | - if ($params['upcomingOnly']) { |
|
| 26 | - return _t('CWP\\CWP\\PageTypes\\EventHolder.Upcoming', 'Upcoming events'); |
|
| 27 | - } |
|
| 22 | + public function getUpdateName() |
|
| 23 | + { |
|
| 24 | + $params = $this->parseParams(); |
|
| 25 | + if ($params['upcomingOnly']) { |
|
| 26 | + return _t('CWP\\CWP\\PageTypes\\EventHolder.Upcoming', 'Upcoming events'); |
|
| 27 | + } |
|
| 28 | 28 | |
| 29 | - return 'Events'; |
|
| 30 | - } |
|
| 29 | + return 'Events'; |
|
| 30 | + } |
|
| 31 | 31 | |
| 32 | - /** |
|
| 33 | - * Parse URL parameters. |
|
| 34 | - * |
|
| 35 | - * @param boolean $produceErrorMessages Set to false to omit session messages. |
|
| 36 | - */ |
|
| 37 | - public function parseParams($produceErrorMessages = true) |
|
| 38 | - { |
|
| 39 | - $params = parent::parseParams($produceErrorMessages); |
|
| 32 | + /** |
|
| 33 | + * Parse URL parameters. |
|
| 34 | + * |
|
| 35 | + * @param boolean $produceErrorMessages Set to false to omit session messages. |
|
| 36 | + */ |
|
| 37 | + public function parseParams($produceErrorMessages = true) |
|
| 38 | + { |
|
| 39 | + $params = parent::parseParams($produceErrorMessages); |
|
| 40 | 40 | |
| 41 | - // We need to set whether or not we're supposed to be displaying only upcoming events or all events. |
|
| 42 | - $params['upcomingOnly'] = !($params['from'] || $params['to'] || $params['year'] || $params['month']); |
|
| 41 | + // We need to set whether or not we're supposed to be displaying only upcoming events or all events. |
|
| 42 | + $params['upcomingOnly'] = !($params['from'] || $params['to'] || $params['year'] || $params['month']); |
|
| 43 | 43 | |
| 44 | - return $params; |
|
| 45 | - } |
|
| 44 | + return $params; |
|
| 45 | + } |
|
| 46 | 46 | |
| 47 | - /** |
|
| 48 | - * Get the events based on the current query. |
|
| 49 | - */ |
|
| 50 | - public function FilteredUpdates($pageSize = 20) |
|
| 51 | - { |
|
| 52 | - $params = $this->parseParams(); |
|
| 47 | + /** |
|
| 48 | + * Get the events based on the current query. |
|
| 49 | + */ |
|
| 50 | + public function FilteredUpdates($pageSize = 20) |
|
| 51 | + { |
|
| 52 | + $params = $this->parseParams(); |
|
| 53 | 53 | |
| 54 | - $items = $this->Updates( |
|
| 55 | - $params['tag'], |
|
| 56 | - $params['from'], |
|
| 57 | - $params['to'], |
|
| 58 | - $params['year'], |
|
| 59 | - $params['month'] |
|
| 60 | - ); |
|
| 54 | + $items = $this->Updates( |
|
| 55 | + $params['tag'], |
|
| 56 | + $params['from'], |
|
| 57 | + $params['to'], |
|
| 58 | + $params['year'], |
|
| 59 | + $params['month'] |
|
| 60 | + ); |
|
| 61 | 61 | |
| 62 | - if ($params['upcomingOnly']) { |
|
| 63 | - $items = $items->filter(['Date:LessThan:Not' => DBDatetime::now()->Format('y-MM-dd')]); |
|
| 64 | - } |
|
| 62 | + if ($params['upcomingOnly']) { |
|
| 63 | + $items = $items->filter(['Date:LessThan:Not' => DBDatetime::now()->Format('y-MM-dd')]); |
|
| 64 | + } |
|
| 65 | 65 | |
| 66 | - // Apply pagination |
|
| 67 | - $list = PaginatedList::create($items, $this->getRequest()); |
|
| 68 | - $list->setPageLength($pageSize); |
|
| 69 | - return $list; |
|
| 70 | - } |
|
| 66 | + // Apply pagination |
|
| 67 | + $list = PaginatedList::create($items, $this->getRequest()); |
|
| 68 | + $list->setPageLength($pageSize); |
|
| 69 | + return $list; |
|
| 70 | + } |
|
| 71 | 71 | } |
@@ -12,81 +12,81 @@ |
||
| 12 | 12 | |
| 13 | 13 | class EventPage extends DatedUpdatePage |
| 14 | 14 | { |
| 15 | - private static $description = 'Describes an event occurring on a specific date.'; |
|
| 16 | - |
|
| 17 | - private static $default_parent = EventHolder::class; |
|
| 18 | - |
|
| 19 | - private static $can_be_root = false; |
|
| 20 | - |
|
| 21 | - private static $icon = 'cwp/cwp:images/icons/sitetree_images/event_page.png'; |
|
| 22 | - |
|
| 23 | - private static $singular_name = 'Event Page'; |
|
| 24 | - |
|
| 25 | - private static $plural_name = 'Event Pages'; |
|
| 26 | - |
|
| 27 | - private static $db = [ |
|
| 28 | - 'StartTime' => 'Time', |
|
| 29 | - 'EndTime' => 'Time', |
|
| 30 | - 'Location' => 'Text', |
|
| 31 | - ]; |
|
| 32 | - |
|
| 33 | - private static $table_name = 'EventPage'; |
|
| 34 | - |
|
| 35 | - public function fieldLabels($includerelations = true) |
|
| 36 | - { |
|
| 37 | - $labels = parent::fieldLabels($includerelations); |
|
| 38 | - $labels['StartTime'] = _t('CWP\\CWP\\PageTypes\\DateUpdatePage.StartTimeFieldLabel', 'Start Time'); |
|
| 39 | - $labels['EndTime'] = _t('CWP\\CWP\\PageTypes\\DateUpdatePage.EndTimeFieldLabel', 'End Time'); |
|
| 40 | - $labels['Location'] = _t('CWP\\CWP\\PageTypes\\DateUpdatePage.LocationFieldLabel', 'Location'); |
|
| 41 | - |
|
| 42 | - return $labels; |
|
| 43 | - } |
|
| 44 | - |
|
| 45 | - /** |
|
| 46 | - * Add the default for the Date being the current day. |
|
| 47 | - */ |
|
| 48 | - public function populateDefaults() |
|
| 49 | - { |
|
| 50 | - if (!isset($this->Date) || $this->Date === null) { |
|
| 51 | - $this->Date = DBDatetime::now()->Format('y-MM-dd'); |
|
| 52 | - } |
|
| 53 | - |
|
| 54 | - if (!isset($this->StartTime) || $this->StartTime === null) { |
|
| 55 | - $this->StartTime = '09:00:00'; |
|
| 56 | - } |
|
| 57 | - |
|
| 58 | - if (!isset($this->EndTime) || $this->EndTime === null) { |
|
| 59 | - $this->EndTime = '17:00:00'; |
|
| 60 | - } |
|
| 61 | - |
|
| 62 | - parent::populateDefaults(); |
|
| 63 | - } |
|
| 64 | - |
|
| 65 | - public function getCMSFields() |
|
| 66 | - { |
|
| 67 | - $this->beforeUpdateCMSFields(function (FieldList $fields) { |
|
| 68 | - $fields->removeByName('Date'); |
|
| 69 | - |
|
| 70 | - $dateTimeFields = array(); |
|
| 71 | - |
|
| 72 | - $dateTimeFields[] = $dateField = DateField::create('Date', 'Date'); |
|
| 73 | - $dateTimeFields[] = $startTimeField = TimeField::create( |
|
| 74 | - 'StartTime', |
|
| 75 | - ' ' . $this->fieldLabel('StartTime') |
|
| 76 | - ); |
|
| 77 | - $dateTimeFields[] = $endTimeField = TimeField::create('EndTime', $this->fieldLabel('EndTime')); |
|
| 78 | - |
|
| 79 | - $fields->addFieldsToTab('Root.Main', [ |
|
| 80 | - $dateTimeField = FieldGroup::create('Date and time', $dateTimeFields), |
|
| 81 | - $locationField = TextareaField::create('Location', $this->fieldLabel('Location')) |
|
| 82 | - ], 'Abstract'); |
|
| 83 | - $locationField->setRows(4); |
|
| 84 | - }); |
|
| 85 | - return parent::getCMSFields(); |
|
| 86 | - } |
|
| 87 | - |
|
| 88 | - public function NiceLocation() |
|
| 89 | - { |
|
| 90 | - return nl2br(Convert::raw2xml($this->Location), true); |
|
| 91 | - } |
|
| 15 | + private static $description = 'Describes an event occurring on a specific date.'; |
|
| 16 | + |
|
| 17 | + private static $default_parent = EventHolder::class; |
|
| 18 | + |
|
| 19 | + private static $can_be_root = false; |
|
| 20 | + |
|
| 21 | + private static $icon = 'cwp/cwp:images/icons/sitetree_images/event_page.png'; |
|
| 22 | + |
|
| 23 | + private static $singular_name = 'Event Page'; |
|
| 24 | + |
|
| 25 | + private static $plural_name = 'Event Pages'; |
|
| 26 | + |
|
| 27 | + private static $db = [ |
|
| 28 | + 'StartTime' => 'Time', |
|
| 29 | + 'EndTime' => 'Time', |
|
| 30 | + 'Location' => 'Text', |
|
| 31 | + ]; |
|
| 32 | + |
|
| 33 | + private static $table_name = 'EventPage'; |
|
| 34 | + |
|
| 35 | + public function fieldLabels($includerelations = true) |
|
| 36 | + { |
|
| 37 | + $labels = parent::fieldLabels($includerelations); |
|
| 38 | + $labels['StartTime'] = _t('CWP\\CWP\\PageTypes\\DateUpdatePage.StartTimeFieldLabel', 'Start Time'); |
|
| 39 | + $labels['EndTime'] = _t('CWP\\CWP\\PageTypes\\DateUpdatePage.EndTimeFieldLabel', 'End Time'); |
|
| 40 | + $labels['Location'] = _t('CWP\\CWP\\PageTypes\\DateUpdatePage.LocationFieldLabel', 'Location'); |
|
| 41 | + |
|
| 42 | + return $labels; |
|
| 43 | + } |
|
| 44 | + |
|
| 45 | + /** |
|
| 46 | + * Add the default for the Date being the current day. |
|
| 47 | + */ |
|
| 48 | + public function populateDefaults() |
|
| 49 | + { |
|
| 50 | + if (!isset($this->Date) || $this->Date === null) { |
|
| 51 | + $this->Date = DBDatetime::now()->Format('y-MM-dd'); |
|
| 52 | + } |
|
| 53 | + |
|
| 54 | + if (!isset($this->StartTime) || $this->StartTime === null) { |
|
| 55 | + $this->StartTime = '09:00:00'; |
|
| 56 | + } |
|
| 57 | + |
|
| 58 | + if (!isset($this->EndTime) || $this->EndTime === null) { |
|
| 59 | + $this->EndTime = '17:00:00'; |
|
| 60 | + } |
|
| 61 | + |
|
| 62 | + parent::populateDefaults(); |
|
| 63 | + } |
|
| 64 | + |
|
| 65 | + public function getCMSFields() |
|
| 66 | + { |
|
| 67 | + $this->beforeUpdateCMSFields(function (FieldList $fields) { |
|
| 68 | + $fields->removeByName('Date'); |
|
| 69 | + |
|
| 70 | + $dateTimeFields = array(); |
|
| 71 | + |
|
| 72 | + $dateTimeFields[] = $dateField = DateField::create('Date', 'Date'); |
|
| 73 | + $dateTimeFields[] = $startTimeField = TimeField::create( |
|
| 74 | + 'StartTime', |
|
| 75 | + ' ' . $this->fieldLabel('StartTime') |
|
| 76 | + ); |
|
| 77 | + $dateTimeFields[] = $endTimeField = TimeField::create('EndTime', $this->fieldLabel('EndTime')); |
|
| 78 | + |
|
| 79 | + $fields->addFieldsToTab('Root.Main', [ |
|
| 80 | + $dateTimeField = FieldGroup::create('Date and time', $dateTimeFields), |
|
| 81 | + $locationField = TextareaField::create('Location', $this->fieldLabel('Location')) |
|
| 82 | + ], 'Abstract'); |
|
| 83 | + $locationField->setRows(4); |
|
| 84 | + }); |
|
| 85 | + return parent::getCMSFields(); |
|
| 86 | + } |
|
| 87 | + |
|
| 88 | + public function NiceLocation() |
|
| 89 | + { |
|
| 90 | + return nl2br(Convert::raw2xml($this->Location), true); |
|
| 91 | + } |
|
| 92 | 92 | } |
@@ -64,7 +64,7 @@ |
||
| 64 | 64 | |
| 65 | 65 | public function getCMSFields() |
| 66 | 66 | { |
| 67 | - $this->beforeUpdateCMSFields(function (FieldList $fields) { |
|
| 67 | + $this->beforeUpdateCMSFields(function(FieldList $fields) { |
|
| 68 | 68 | $fields->removeByName('Date'); |
| 69 | 69 | |
| 70 | 70 | $dateTimeFields = array(); |
@@ -9,55 +9,55 @@ |
||
| 9 | 9 | |
| 10 | 10 | class NewsPage extends DatedUpdatePage |
| 11 | 11 | { |
| 12 | - private static $description = 'Describes an item of news'; |
|
| 12 | + private static $description = 'Describes an item of news'; |
|
| 13 | 13 | |
| 14 | - private static $default_parent = 'NewsHolderPage'; |
|
| 14 | + private static $default_parent = 'NewsHolderPage'; |
|
| 15 | 15 | |
| 16 | - private static $can_be_root = false; |
|
| 16 | + private static $can_be_root = false; |
|
| 17 | 17 | |
| 18 | - private static $icon = 'cwp/cwp:images/icons/sitetree_images/news.png'; |
|
| 18 | + private static $icon = 'cwp/cwp:images/icons/sitetree_images/news.png'; |
|
| 19 | 19 | |
| 20 | - private static $singular_name = 'News Page'; |
|
| 20 | + private static $singular_name = 'News Page'; |
|
| 21 | 21 | |
| 22 | - private static $plural_name = 'News Pages'; |
|
| 22 | + private static $plural_name = 'News Pages'; |
|
| 23 | 23 | |
| 24 | - private static $db = [ |
|
| 25 | - 'Author' => 'Varchar(255)', |
|
| 26 | - ]; |
|
| 24 | + private static $db = [ |
|
| 25 | + 'Author' => 'Varchar(255)', |
|
| 26 | + ]; |
|
| 27 | 27 | |
| 28 | - private static $has_one = [ |
|
| 29 | - 'FeaturedImage' => Image::class, |
|
| 30 | - ]; |
|
| 28 | + private static $has_one = [ |
|
| 29 | + 'FeaturedImage' => Image::class, |
|
| 30 | + ]; |
|
| 31 | 31 | |
| 32 | - private static $table_name = 'NewsPage'; |
|
| 32 | + private static $table_name = 'NewsPage'; |
|
| 33 | 33 | |
| 34 | - public function fieldLabels($includerelations = true) |
|
| 35 | - { |
|
| 36 | - $labels = parent::fieldLabels($includerelations); |
|
| 37 | - $labels['Author'] = _t('CWP\\CWP\\PageTypes\\DateUpdatePage.AuthorFieldLabel', 'Author'); |
|
| 38 | - $labels['FeaturedImageID'] = _t( |
|
| 39 | - 'CWP\\CWP\\PageTypes\\DateUpdatePage.FeaturedImageFieldLabel', |
|
| 40 | - 'Featured Image' |
|
| 41 | - ); |
|
| 34 | + public function fieldLabels($includerelations = true) |
|
| 35 | + { |
|
| 36 | + $labels = parent::fieldLabels($includerelations); |
|
| 37 | + $labels['Author'] = _t('CWP\\CWP\\PageTypes\\DateUpdatePage.AuthorFieldLabel', 'Author'); |
|
| 38 | + $labels['FeaturedImageID'] = _t( |
|
| 39 | + 'CWP\\CWP\\PageTypes\\DateUpdatePage.FeaturedImageFieldLabel', |
|
| 40 | + 'Featured Image' |
|
| 41 | + ); |
|
| 42 | 42 | |
| 43 | - return $labels; |
|
| 44 | - } |
|
| 43 | + return $labels; |
|
| 44 | + } |
|
| 45 | 45 | |
| 46 | - public function getCMSFields() |
|
| 47 | - { |
|
| 48 | - $this->beforeUpdateCMSFields(function (FieldList $fields) { |
|
| 49 | - $fields->addFieldToTab( |
|
| 50 | - 'Root.Main', |
|
| 51 | - TextField::create('Author', $this->fieldLabel('Author')), |
|
| 52 | - 'Abstract' |
|
| 53 | - ); |
|
| 46 | + public function getCMSFields() |
|
| 47 | + { |
|
| 48 | + $this->beforeUpdateCMSFields(function (FieldList $fields) { |
|
| 49 | + $fields->addFieldToTab( |
|
| 50 | + 'Root.Main', |
|
| 51 | + TextField::create('Author', $this->fieldLabel('Author')), |
|
| 52 | + 'Abstract' |
|
| 53 | + ); |
|
| 54 | 54 | |
| 55 | - $fields->addFieldToTab( |
|
| 56 | - 'Root.Main', |
|
| 57 | - UploadField::create('FeaturedImage', $this->fieldLabel('FeaturedImageID')), |
|
| 58 | - 'Abstract' |
|
| 59 | - ); |
|
| 60 | - }); |
|
| 61 | - return parent::getCMSFields(); |
|
| 62 | - } |
|
| 55 | + $fields->addFieldToTab( |
|
| 56 | + 'Root.Main', |
|
| 57 | + UploadField::create('FeaturedImage', $this->fieldLabel('FeaturedImageID')), |
|
| 58 | + 'Abstract' |
|
| 59 | + ); |
|
| 60 | + }); |
|
| 61 | + return parent::getCMSFields(); |
|
| 62 | + } |
|
| 63 | 63 | } |
@@ -45,7 +45,7 @@ |
||
| 45 | 45 | |
| 46 | 46 | public function getCMSFields() |
| 47 | 47 | { |
| 48 | - $this->beforeUpdateCMSFields(function (FieldList $fields) { |
|
| 48 | + $this->beforeUpdateCMSFields(function(FieldList $fields) { |
|
| 49 | 49 | $fields->addFieldToTab( |
| 50 | 50 | 'Root.Main', |
| 51 | 51 | TextField::create('Author', $this->fieldLabel('Author')), |
@@ -9,26 +9,26 @@ |
||
| 9 | 9 | |
| 10 | 10 | class CleanupGeneratedPdfDailyTaskTest extends SapphireTest |
| 11 | 11 | { |
| 12 | - /** |
|
| 13 | - * @var CleanupGeneratedPdfDailyTask |
|
| 14 | - */ |
|
| 15 | - protected $task; |
|
| 12 | + /** |
|
| 13 | + * @var CleanupGeneratedPdfDailyTask |
|
| 14 | + */ |
|
| 15 | + protected $task; |
|
| 16 | 16 | |
| 17 | - protected function setUp() |
|
| 18 | - { |
|
| 19 | - parent::setUp(); |
|
| 17 | + protected function setUp() |
|
| 18 | + { |
|
| 19 | + parent::setUp(); |
|
| 20 | 20 | |
| 21 | - if (!interface_exists(CronTask::class)) { |
|
| 22 | - $this->markTestSkipped('Test class requires the silverstripe/crontask module to be installed'); |
|
| 23 | - } |
|
| 21 | + if (!interface_exists(CronTask::class)) { |
|
| 22 | + $this->markTestSkipped('Test class requires the silverstripe/crontask module to be installed'); |
|
| 23 | + } |
|
| 24 | 24 | |
| 25 | - $this->task = new CleanupGeneratedPdfDailyTask(); |
|
| 26 | - } |
|
| 25 | + $this->task = new CleanupGeneratedPdfDailyTask(); |
|
| 26 | + } |
|
| 27 | 27 | |
| 28 | - public function testCronScheduleIsConfigurable() |
|
| 29 | - { |
|
| 30 | - Config::modify()->set(CleanupGeneratedPdfDailyTask::class, 'schedule', '* 1 2 3 *'); |
|
| 28 | + public function testCronScheduleIsConfigurable() |
|
| 29 | + { |
|
| 30 | + Config::modify()->set(CleanupGeneratedPdfDailyTask::class, 'schedule', '* 1 2 3 *'); |
|
| 31 | 31 | |
| 32 | - $this->assertSame('* 1 2 3 *', $this->task->getSchedule()); |
|
| 33 | - } |
|
| 32 | + $this->assertSame('* 1 2 3 *', $this->task->getSchedule()); |
|
| 33 | + } |
|
| 34 | 34 | } |
@@ -7,7 +7,7 @@ discard block |
||
| 7 | 7 | use SilverStripe\CronTask\Interfaces\CronTask; |
| 8 | 8 | |
| 9 | 9 | if (!interface_exists(CronTask::class)) { |
| 10 | - return; |
|
| 10 | + return; |
|
| 11 | 11 | } |
| 12 | 12 | |
| 13 | 13 | /** |
@@ -15,36 +15,36 @@ discard block |
||
| 15 | 15 | */ |
| 16 | 16 | class CleanupGeneratedPdfDailyTask implements CronTask |
| 17 | 17 | { |
| 18 | - use Configurable; |
|
| 19 | - |
|
| 20 | - /** |
|
| 21 | - * The cron schedule for this task (default: midnight every day) |
|
| 22 | - * |
|
| 23 | - * @config |
|
| 24 | - * @var string |
|
| 25 | - */ |
|
| 26 | - private static $schedule = '0 0 * * *'; |
|
| 27 | - |
|
| 28 | - /** |
|
| 29 | - * Whether this task is enabled (default false) |
|
| 30 | - * |
|
| 31 | - * @config |
|
| 32 | - * @return bool |
|
| 33 | - */ |
|
| 34 | - private static $enabled = false; |
|
| 35 | - |
|
| 36 | - public function getSchedule() |
|
| 37 | - { |
|
| 38 | - return $this->config()->get('schedule'); |
|
| 39 | - } |
|
| 40 | - |
|
| 41 | - public function process() |
|
| 42 | - { |
|
| 43 | - if (!$this->config()->get('enabled')) { |
|
| 44 | - return; |
|
| 45 | - } |
|
| 46 | - |
|
| 47 | - $task = Injector::inst()->create(CleanupGeneratedPdfBuildTask::class); |
|
| 48 | - $task->run(null); |
|
| 49 | - } |
|
| 18 | + use Configurable; |
|
| 19 | + |
|
| 20 | + /** |
|
| 21 | + * The cron schedule for this task (default: midnight every day) |
|
| 22 | + * |
|
| 23 | + * @config |
|
| 24 | + * @var string |
|
| 25 | + */ |
|
| 26 | + private static $schedule = '0 0 * * *'; |
|
| 27 | + |
|
| 28 | + /** |
|
| 29 | + * Whether this task is enabled (default false) |
|
| 30 | + * |
|
| 31 | + * @config |
|
| 32 | + * @return bool |
|
| 33 | + */ |
|
| 34 | + private static $enabled = false; |
|
| 35 | + |
|
| 36 | + public function getSchedule() |
|
| 37 | + { |
|
| 38 | + return $this->config()->get('schedule'); |
|
| 39 | + } |
|
| 40 | + |
|
| 41 | + public function process() |
|
| 42 | + { |
|
| 43 | + if (!$this->config()->get('enabled')) { |
|
| 44 | + return; |
|
| 45 | + } |
|
| 46 | + |
|
| 47 | + $task = Injector::inst()->create(CleanupGeneratedPdfBuildTask::class); |
|
| 48 | + $task->run(null); |
|
| 49 | + } |
|
| 50 | 50 | } |
@@ -7,24 +7,24 @@ |
||
| 7 | 7 | |
| 8 | 8 | class CleanupGeneratedPdfBuildTask extends BuildTask |
| 9 | 9 | { |
| 10 | - protected $title = 'Cleanup generated PDFs'; |
|
| 10 | + protected $title = 'Cleanup generated PDFs'; |
|
| 11 | 11 | |
| 12 | - protected $description = 'Removes generated PDFs on the site, forcing a regeneration of all exports to PDF ' |
|
| 13 | - . 'when users go to download them. This is most useful when templates have been changed so users should ' |
|
| 14 | - . 'receive a new copy'; |
|
| 12 | + protected $description = 'Removes generated PDFs on the site, forcing a regeneration of all exports to PDF ' |
|
| 13 | + . 'when users go to download them. This is most useful when templates have been changed so users should ' |
|
| 14 | + . 'receive a new copy'; |
|
| 15 | 15 | |
| 16 | - public function run($request) |
|
| 17 | - { |
|
| 18 | - $path = sprintf('%s/%s', BASE_PATH, BasePage::config()->get('generated_pdf_path')); |
|
| 19 | - if (!file_exists($path)) { |
|
| 20 | - return false; |
|
| 21 | - } |
|
| 16 | + public function run($request) |
|
| 17 | + { |
|
| 18 | + $path = sprintf('%s/%s', BASE_PATH, BasePage::config()->get('generated_pdf_path')); |
|
| 19 | + if (!file_exists($path)) { |
|
| 20 | + return false; |
|
| 21 | + } |
|
| 22 | 22 | |
| 23 | - exec(sprintf('if [ "$(ls -A %s 2> /dev/null)" != "" ]; then rm %s/*; fi', $path, $path), $output, $return_val); |
|
| 23 | + exec(sprintf('if [ "$(ls -A %s 2> /dev/null)" != "" ]; then rm %s/*; fi', $path, $path), $output, $return_val); |
|
| 24 | 24 | |
| 25 | - // output any errors |
|
| 26 | - if ($return_val != 0) { |
|
| 27 | - user_error(sprintf('%s failed: ', get_class($this)) . implode("\n", $output), E_USER_ERROR); |
|
| 28 | - } |
|
| 29 | - } |
|
| 25 | + // output any errors |
|
| 26 | + if ($return_val != 0) { |
|
| 27 | + user_error(sprintf('%s failed: ', get_class($this)) . implode("\n", $output), E_USER_ERROR); |
|
| 28 | + } |
|
| 29 | + } |
|
| 30 | 30 | } |
@@ -11,16 +11,16 @@ |
||
| 11 | 11 | */ |
| 12 | 12 | class CwpSearchPage extends Page |
| 13 | 13 | { |
| 14 | - private static $hide_ancestor = CwpSearchPage::class; |
|
| 14 | + private static $hide_ancestor = CwpSearchPage::class; |
|
| 15 | 15 | |
| 16 | - private static $table_name = 'CwpSearchPage'; |
|
| 16 | + private static $table_name = 'CwpSearchPage'; |
|
| 17 | 17 | |
| 18 | - public function canViewStage($stage = Versioned::LIVE, $member = null) |
|
| 19 | - { |
|
| 20 | - if (Permission::checkMember($member, 'VIEW_DRAFT_CONTENT')) { |
|
| 21 | - return true; |
|
| 22 | - } |
|
| 18 | + public function canViewStage($stage = Versioned::LIVE, $member = null) |
|
| 19 | + { |
|
| 20 | + if (Permission::checkMember($member, 'VIEW_DRAFT_CONTENT')) { |
|
| 21 | + return true; |
|
| 22 | + } |
|
| 23 | 23 | |
| 24 | - return parent::canViewStage($stage, $member); |
|
| 25 | - } |
|
| 24 | + return parent::canViewStage($stage, $member); |
|
| 25 | + } |
|
| 26 | 26 | } |
@@ -7,42 +7,42 @@ |
||
| 7 | 7 | |
| 8 | 8 | class SitemapPageController extends PageController |
| 9 | 9 | { |
| 10 | - private static $allowed_actions = [ |
|
| 11 | - 'showpage', |
|
| 12 | - ]; |
|
| 13 | - |
|
| 14 | - private static $url_handlers = [ |
|
| 15 | - 'page/$ID' => 'showpage', |
|
| 16 | - ]; |
|
| 17 | - |
|
| 18 | - public function showpage($request) |
|
| 19 | - { |
|
| 20 | - $id = (int) $request->param('ID'); |
|
| 21 | - if (!$id) { |
|
| 22 | - return false; |
|
| 23 | - } |
|
| 24 | - $page = SiteTree::get()->byId($id); |
|
| 25 | - |
|
| 26 | - // does the page exist? |
|
| 27 | - if (!($page && $page->exists())) { |
|
| 28 | - return $this->httpError(404); |
|
| 29 | - } |
|
| 30 | - |
|
| 31 | - // can the page be viewed? |
|
| 32 | - if (!$page->canView()) { |
|
| 33 | - return $this->httpError(403); |
|
| 34 | - } |
|
| 35 | - |
|
| 36 | - $viewer = $this->customise([ |
|
| 37 | - 'IsAjax' => $request->isAjax(), |
|
| 38 | - 'SelectedPage' => $page, |
|
| 39 | - 'Children' => $page->Children(), |
|
| 40 | - ]); |
|
| 41 | - |
|
| 42 | - if ($request->isAjax()) { |
|
| 43 | - return $viewer->renderWith('SitemapNodeChildren'); |
|
| 44 | - } |
|
| 45 | - |
|
| 46 | - return $viewer; |
|
| 47 | - } |
|
| 10 | + private static $allowed_actions = [ |
|
| 11 | + 'showpage', |
|
| 12 | + ]; |
|
| 13 | + |
|
| 14 | + private static $url_handlers = [ |
|
| 15 | + 'page/$ID' => 'showpage', |
|
| 16 | + ]; |
|
| 17 | + |
|
| 18 | + public function showpage($request) |
|
| 19 | + { |
|
| 20 | + $id = (int) $request->param('ID'); |
|
| 21 | + if (!$id) { |
|
| 22 | + return false; |
|
| 23 | + } |
|
| 24 | + $page = SiteTree::get()->byId($id); |
|
| 25 | + |
|
| 26 | + // does the page exist? |
|
| 27 | + if (!($page && $page->exists())) { |
|
| 28 | + return $this->httpError(404); |
|
| 29 | + } |
|
| 30 | + |
|
| 31 | + // can the page be viewed? |
|
| 32 | + if (!$page->canView()) { |
|
| 33 | + return $this->httpError(403); |
|
| 34 | + } |
|
| 35 | + |
|
| 36 | + $viewer = $this->customise([ |
|
| 37 | + 'IsAjax' => $request->isAjax(), |
|
| 38 | + 'SelectedPage' => $page, |
|
| 39 | + 'Children' => $page->Children(), |
|
| 40 | + ]); |
|
| 41 | + |
|
| 42 | + if ($request->isAjax()) { |
|
| 43 | + return $viewer->renderWith('SitemapNodeChildren'); |
|
| 44 | + } |
|
| 45 | + |
|
| 46 | + return $viewer; |
|
| 47 | + } |
|
| 48 | 48 | } |
@@ -17,141 +17,141 @@ |
||
| 17 | 17 | */ |
| 18 | 18 | class CwpSearchEngine |
| 19 | 19 | { |
| 20 | - use Configurable; |
|
| 21 | - use Extensible; |
|
| 22 | - use Injectable; |
|
| 23 | - |
|
| 24 | - /** |
|
| 25 | - * Default search options |
|
| 26 | - * |
|
| 27 | - * @var array |
|
| 28 | - * @config |
|
| 29 | - */ |
|
| 30 | - private static $search_options = [ |
|
| 31 | - 'hl' => 'true', |
|
| 32 | - ]; |
|
| 33 | - |
|
| 34 | - /** |
|
| 35 | - * Additional search options to send to search when spellcheck |
|
| 36 | - * is included |
|
| 37 | - * |
|
| 38 | - * @var array |
|
| 39 | - * @config |
|
| 40 | - */ |
|
| 41 | - private static $spellcheck_options = [ |
|
| 42 | - 'spellcheck' => 'true', |
|
| 43 | - 'spellcheck.collate' => 'true', |
|
| 44 | - // spellcheck.dictionary can also be configured to use '_spellcheck' |
|
| 45 | - // dictionary when indexing fields under the _spellcheckText column |
|
| 46 | - 'spellcheck.dictionary' => 'default', |
|
| 47 | - ]; |
|
| 48 | - |
|
| 49 | - /** |
|
| 50 | - * Build a SearchQuery for a new search |
|
| 51 | - * |
|
| 52 | - * @param string $keywords |
|
| 53 | - * @param array $classes |
|
| 54 | - * @return SearchQuery |
|
| 55 | - */ |
|
| 56 | - protected function getSearchQuery($keywords, $classes) |
|
| 57 | - { |
|
| 58 | - $query = new SearchQuery(); |
|
| 59 | - $query->classes = $classes; |
|
| 60 | - $query->search($keywords); |
|
| 61 | - $query->exclude(SiteTree::class . '_ShowInSearch', 0); |
|
| 62 | - |
|
| 63 | - // Artificially lower the amount of results to prevent too high resource usage. |
|
| 64 | - // on subsequent canView check loop. |
|
| 65 | - $query->limit(100); |
|
| 66 | - |
|
| 67 | - // Allow user code to modify the search query before returning it |
|
| 68 | - $this->extend('updateSearchQuery', $query); |
|
| 69 | - |
|
| 70 | - return $query; |
|
| 71 | - } |
|
| 72 | - |
|
| 73 | - /** |
|
| 74 | - * Get solr search options for this query |
|
| 75 | - * |
|
| 76 | - * @param bool $spellcheck True if we should include spellcheck support |
|
| 77 | - * @return array |
|
| 78 | - */ |
|
| 79 | - protected function getSearchOptions($spellcheck) |
|
| 80 | - { |
|
| 81 | - $options = $this->config()->get('search_options'); |
|
| 82 | - if ($spellcheck) { |
|
| 83 | - $options = array_merge($options, $this->config()->get('spellcheck_options')); |
|
| 84 | - } |
|
| 85 | - return $options; |
|
| 86 | - } |
|
| 87 | - |
|
| 88 | - /** |
|
| 89 | - * Get results for a search term |
|
| 90 | - * |
|
| 91 | - * @param string $keywords |
|
| 92 | - * @param array $classes |
|
| 93 | - * @param SolrIndex $searchIndex |
|
| 94 | - * @param int $limit Max number of results for this page |
|
| 95 | - * @param int $start Skip this number of records |
|
| 96 | - * @param bool $spellcheck True to enable spellcheck |
|
| 97 | - * @return CwpSearchResult |
|
| 98 | - */ |
|
| 99 | - protected function getResult($keywords, $classes, $searchIndex, $limit = -1, $start = 0, $spellcheck = false) |
|
| 100 | - { |
|
| 101 | - // Prepare options |
|
| 102 | - $query = $this->getSearchQuery($keywords, $classes); |
|
| 103 | - $options = $this->getSearchOptions($spellcheck); |
|
| 104 | - |
|
| 105 | - // Get results |
|
| 106 | - $solrResult = $searchIndex->search( |
|
| 107 | - $query, |
|
| 108 | - $start, |
|
| 109 | - $limit, |
|
| 110 | - $options |
|
| 111 | - ); |
|
| 112 | - |
|
| 113 | - return CwpSearchResult::create($keywords, $solrResult); |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - /** |
|
| 117 | - * Get a CwpSearchResult for a given criterea |
|
| 118 | - * |
|
| 119 | - * @param string $keywords |
|
| 120 | - * @param array $classes |
|
| 121 | - * @param SolrIndex $searchIndex |
|
| 122 | - * @param int $limit Max number of results for this page |
|
| 123 | - * @param int $start Skip this number of records |
|
| 124 | - * @param bool $followSuggestions True to enable suggested searches to be returned immediately |
|
| 125 | - * @return CwpSearchResult|null |
|
| 126 | - */ |
|
| 127 | - public function search($keywords, $classes, $searchIndex, $limit = -1, $start = 0, $followSuggestions = false) |
|
| 128 | - { |
|
| 129 | - if (empty($keywords)) { |
|
| 130 | - return null; |
|
| 131 | - } |
|
| 132 | - |
|
| 133 | - try { |
|
| 134 | - // Begin search |
|
| 135 | - $result = $this->getResult($keywords, $classes, $searchIndex, $limit, $start, true); |
|
| 136 | - |
|
| 137 | - // Return results if we don't need to refine this any further |
|
| 138 | - if (!$followSuggestions || $result->hasResults() || !$result->getSuggestion()) { |
|
| 139 | - return $result; |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - // Perform new search with the suggested terms |
|
| 143 | - $suggested = $result->getSuggestion(); |
|
| 144 | - $newResult = $this->getResult($suggested, $classes, $searchIndex, $limit, $start, false); |
|
| 145 | - $newResult->setOriginal($keywords); |
|
| 146 | - |
|
| 147 | - // Compare new results to the original query |
|
| 148 | - if ($newResult->hasResults()) { |
|
| 149 | - return $newResult; |
|
| 150 | - } |
|
| 151 | - |
|
| 152 | - return $result; |
|
| 153 | - } catch (Exception $e) { |
|
| 154 | - Injector::inst()->get(LoggerInterface::class)->warning($e); |
|
| 155 | - } |
|
| 156 | - } |
|
| 20 | + use Configurable; |
|
| 21 | + use Extensible; |
|
| 22 | + use Injectable; |
|
| 23 | + |
|
| 24 | + /** |
|
| 25 | + * Default search options |
|
| 26 | + * |
|
| 27 | + * @var array |
|
| 28 | + * @config |
|
| 29 | + */ |
|
| 30 | + private static $search_options = [ |
|
| 31 | + 'hl' => 'true', |
|
| 32 | + ]; |
|
| 33 | + |
|
| 34 | + /** |
|
| 35 | + * Additional search options to send to search when spellcheck |
|
| 36 | + * is included |
|
| 37 | + * |
|
| 38 | + * @var array |
|
| 39 | + * @config |
|
| 40 | + */ |
|
| 41 | + private static $spellcheck_options = [ |
|
| 42 | + 'spellcheck' => 'true', |
|
| 43 | + 'spellcheck.collate' => 'true', |
|
| 44 | + // spellcheck.dictionary can also be configured to use '_spellcheck' |
|
| 45 | + // dictionary when indexing fields under the _spellcheckText column |
|
| 46 | + 'spellcheck.dictionary' => 'default', |
|
| 47 | + ]; |
|
| 48 | + |
|
| 49 | + /** |
|
| 50 | + * Build a SearchQuery for a new search |
|
| 51 | + * |
|
| 52 | + * @param string $keywords |
|
| 53 | + * @param array $classes |
|
| 54 | + * @return SearchQuery |
|
| 55 | + */ |
|
| 56 | + protected function getSearchQuery($keywords, $classes) |
|
| 57 | + { |
|
| 58 | + $query = new SearchQuery(); |
|
| 59 | + $query->classes = $classes; |
|
| 60 | + $query->search($keywords); |
|
| 61 | + $query->exclude(SiteTree::class . '_ShowInSearch', 0); |
|
| 62 | + |
|
| 63 | + // Artificially lower the amount of results to prevent too high resource usage. |
|
| 64 | + // on subsequent canView check loop. |
|
| 65 | + $query->limit(100); |
|
| 66 | + |
|
| 67 | + // Allow user code to modify the search query before returning it |
|
| 68 | + $this->extend('updateSearchQuery', $query); |
|
| 69 | + |
|
| 70 | + return $query; |
|
| 71 | + } |
|
| 72 | + |
|
| 73 | + /** |
|
| 74 | + * Get solr search options for this query |
|
| 75 | + * |
|
| 76 | + * @param bool $spellcheck True if we should include spellcheck support |
|
| 77 | + * @return array |
|
| 78 | + */ |
|
| 79 | + protected function getSearchOptions($spellcheck) |
|
| 80 | + { |
|
| 81 | + $options = $this->config()->get('search_options'); |
|
| 82 | + if ($spellcheck) { |
|
| 83 | + $options = array_merge($options, $this->config()->get('spellcheck_options')); |
|
| 84 | + } |
|
| 85 | + return $options; |
|
| 86 | + } |
|
| 87 | + |
|
| 88 | + /** |
|
| 89 | + * Get results for a search term |
|
| 90 | + * |
|
| 91 | + * @param string $keywords |
|
| 92 | + * @param array $classes |
|
| 93 | + * @param SolrIndex $searchIndex |
|
| 94 | + * @param int $limit Max number of results for this page |
|
| 95 | + * @param int $start Skip this number of records |
|
| 96 | + * @param bool $spellcheck True to enable spellcheck |
|
| 97 | + * @return CwpSearchResult |
|
| 98 | + */ |
|
| 99 | + protected function getResult($keywords, $classes, $searchIndex, $limit = -1, $start = 0, $spellcheck = false) |
|
| 100 | + { |
|
| 101 | + // Prepare options |
|
| 102 | + $query = $this->getSearchQuery($keywords, $classes); |
|
| 103 | + $options = $this->getSearchOptions($spellcheck); |
|
| 104 | + |
|
| 105 | + // Get results |
|
| 106 | + $solrResult = $searchIndex->search( |
|
| 107 | + $query, |
|
| 108 | + $start, |
|
| 109 | + $limit, |
|
| 110 | + $options |
|
| 111 | + ); |
|
| 112 | + |
|
| 113 | + return CwpSearchResult::create($keywords, $solrResult); |
|
| 114 | + } |
|
| 115 | + |
|
| 116 | + /** |
|
| 117 | + * Get a CwpSearchResult for a given criterea |
|
| 118 | + * |
|
| 119 | + * @param string $keywords |
|
| 120 | + * @param array $classes |
|
| 121 | + * @param SolrIndex $searchIndex |
|
| 122 | + * @param int $limit Max number of results for this page |
|
| 123 | + * @param int $start Skip this number of records |
|
| 124 | + * @param bool $followSuggestions True to enable suggested searches to be returned immediately |
|
| 125 | + * @return CwpSearchResult|null |
|
| 126 | + */ |
|
| 127 | + public function search($keywords, $classes, $searchIndex, $limit = -1, $start = 0, $followSuggestions = false) |
|
| 128 | + { |
|
| 129 | + if (empty($keywords)) { |
|
| 130 | + return null; |
|
| 131 | + } |
|
| 132 | + |
|
| 133 | + try { |
|
| 134 | + // Begin search |
|
| 135 | + $result = $this->getResult($keywords, $classes, $searchIndex, $limit, $start, true); |
|
| 136 | + |
|
| 137 | + // Return results if we don't need to refine this any further |
|
| 138 | + if (!$followSuggestions || $result->hasResults() || !$result->getSuggestion()) { |
|
| 139 | + return $result; |
|
| 140 | + } |
|
| 141 | + |
|
| 142 | + // Perform new search with the suggested terms |
|
| 143 | + $suggested = $result->getSuggestion(); |
|
| 144 | + $newResult = $this->getResult($suggested, $classes, $searchIndex, $limit, $start, false); |
|
| 145 | + $newResult->setOriginal($keywords); |
|
| 146 | + |
|
| 147 | + // Compare new results to the original query |
|
| 148 | + if ($newResult->hasResults()) { |
|
| 149 | + return $newResult; |
|
| 150 | + } |
|
| 151 | + |
|
| 152 | + return $result; |
|
| 153 | + } catch (Exception $e) { |
|
| 154 | + Injector::inst()->get(LoggerInterface::class)->warning($e); |
|
| 155 | + } |
|
| 156 | + } |
|
| 157 | 157 | } |