Skip to content

Commit

Permalink
API Deprecate API that will be removed (#203)
Browse files Browse the repository at this point in the history
  • Loading branch information
GuySartorelli authored Sep 13, 2024
1 parent edbda80 commit d42ca25
Showing 1 changed file with 27 additions and 14 deletions.
41 changes: 27 additions & 14 deletions src/Task/StaticCacheFullBuildTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use SilverStripe\Control\HTTPRequest;
use SilverStripe\Core\Injector\Injector;
use SilverStripe\Dev\BuildTask;
use SilverStripe\Dev\Deprecation;
use SilverStripe\ORM\DataList;
use SilverStripe\ORM\FieldType\DBDatetime;
use SilverStripe\StaticPublishQueue\Job\StaticCacheFullBuildJob;
Expand Down Expand Up @@ -42,12 +43,14 @@ public function run($request)
$existing = DataList::create(QueuedJobDescriptor::class)->filter($filter)->first();

if ($existing && $existing->exists()) {
$this->log(sprintf(
'There is already a %s in the queue, added %s %s',
StaticCacheFullBuildJob::class,
$existing->Created,
$existing->StartAfter ? 'and set to start after ' . $existing->StartAfter : ''
));
Deprecation::withNoReplacement(function () use ($existing) {
$this->log(sprintf(
'There is already a %s in the queue, added %s %s',
StaticCacheFullBuildJob::class,
$existing->Created,
$existing->StartAfter ? 'and set to start after ' . $existing->StartAfter : ''
));
});

return false;
}
Expand All @@ -71,20 +74,26 @@ public function run($request)

// sanity check that we are in the next 24 hours - prevents some weird stuff sneaking through
if ($startAfter->getTimestamp() > $thisTimeTomorrow || $startAfter->getTimestamp() < $now->getTimestamp()) {
$this->log('Invalid startAfter parameter passed. Please ensure the time format is HHmm e.g. 1300');
Deprecation::withNoReplacement(function () {
$this->log('Invalid startAfter parameter passed. Please ensure the time format is HHmm e.g. 1300');
});

return false;
}

$this->log(sprintf(
'%s queued for %s %s.',
StaticCacheFullBuildJob::class,
$startAfter->format('H:m'),
$dayWord
));
Deprecation::withNoReplacement(function () use ($startAfter, $dayWord) {
$this->log(sprintf(
'%s queued for %s %s.',
StaticCacheFullBuildJob::class,
$startAfter->format('H:m'),
$dayWord
));
});
} else {
$startAfter = null;
$this->log(StaticCacheFullBuildJob::class . ' added to the queue for immediate processing');
Deprecation::withNoReplacement(function () {
$this->log(StaticCacheFullBuildJob::class . ' added to the queue for immediate processing');
});
}

$job->setJobData(0, 0, false, new \stdClass(), [
Expand All @@ -95,8 +104,12 @@ public function run($request)
return true;
}

/**
* @deprecated 6.3.0 Will be replaced with new $output parameter in the run() method
*/
protected function log($message)
{
Deprecation::notice('6.3.0', 'Will be replaced with new $output parameter in the run() method');
$newLine = Director::is_cli() ? PHP_EOL : '<br>';
echo $message . $newLine;
}
Expand Down

0 comments on commit d42ca25

Please sign in to comment.