silverstripe / silverstripe-staticpublishqueue

This module allows you to build static HTML caches of every page (for increased security and performance)
BSD 3-Clause "New" or "Revised" License
46 stars 57 forks source link

BUG: Recursive publish hook. #133

Closed mfendeksilverstripe closed 3 years ago

mfendeksilverstripe commented 3 years ago

Publishing engine trigger

Publishing engine now triggers onAfterPublishRecursive instead of onAfterPublish which fixes a lot of problems when dealing with pages which contains a lot of nested models like blocks. This ensures that URL collection starts after all models in the publishRecursive batch are published.

Related issues

https://github.com/silverstripe/silverstripe-staticpublishqueue/issues/134

Issues with tests

Unit tests are passing but the build is failing due to some QueuedJobs related issue. This is likely some registered shutdown function which is called near the end of the test suite run. I couldn't reproduce this on my local (vanilla install).

I added some logging to see the stack trace of the exception:

#0 /home/travis/build/silverstripe/silverstripe-staticpublishqueue/src/Dev/TestPdoConnector.php(14): SilverStripe\ORM\Connect\DBConnector->databaseError('Couldn't run qu...', 256, 'SELECT DISTINCT...', Array)
#1 /home/travis/build/silverstripe/silverstripe-staticpublishqueue/vendor/silverstripe/framework/src/ORM/Connect/PDOConnector.php(417): SilverStripe\StaticPublishQueue\Dev\TestPdoConnector->databaseError('3D000-1046: No ...', 256, 'SELECT DISTINCT...', Array)
#2 /home/travis/build/silverstripe/silverstripe-staticpublishqueue/vendor/silverstripe/framework/src/ORM/Connect/Database.php(185): SilverStripe\ORM\Connect\PDOConnector->preparedQuery('SELECT DISTINCT...', Array, 256)
#3 /home/travis/build/silverstripe/silverstripe-staticpublishqueue/vendor/silverstripe/framework/src/ORM/Connect/Database.php(258): SilverStripe\ORM\Connect\Database->SilverStripe\ORM\Connect\{closure}('SELECT DISTINCT...')
#4 /home/travis/build/silverstripe/silverstripe-staticpublishqueue/vendor/silverstripe/framework/src/ORM/Connect/Database.php(183): SilverStripe\ORM\Connect\Database->benchmarkQuery('SELECT DISTINCT...', Object(Closure), Array)
#5 /home/travis/build/silverstripe/silverstripe-staticpublishqueue/vendor/silverstripe/framework/src/ORM/Connect/MySQLDatabase.php(393): SilverStripe\ORM\Connect\Database->preparedQuery('SELECT DISTINCT...', Array, 256)
#6 /home/travis/build/silverstripe/silverstripe-staticpublishqueue/vendor/silverstripe/framework/src/ORM/DB.php(445): SilverStripe\ORM\Connect\MySQLDatabase->preparedQuery('SELECT DISTINCT...', Array, 256)
#7 /home/travis/build/silverstripe/silverstripe-staticpublishqueue/vendor/silverstripe/framework/src/ORM/Queries/SQLExpression.php(115): SilverStripe\ORM\DB::prepared_query('SELECT DISTINCT...', Array)
#8 /home/travis/build/silverstripe/silverstripe-staticpublishqueue/vendor/silverstripe/framework/src/ORM/DataList.php(933): SilverStripe\ORM\Queries\SQLExpression->execute()
#9 /home/travis/build/silverstripe/silverstripe-staticpublishqueue/vendor/silverstripe/framework/src/ORM/DataList.php(971): SilverStripe\ORM\DataList->first()
#10 /home/travis/build/silverstripe/silverstripe-staticpublishqueue/vendor/symbiote/silverstripe-queuedjobs/src/Services/QueuedJobService.php(391): SilverStripe\ORM\DataList->find('JobStatus', 'Waiting')
#11 /home/travis/build/silverstripe/silverstripe-staticpublishqueue/vendor/symbiote/silverstripe-queuedjobs/src/Services/QueuedJobService.php(1369): Symbiote\QueuedJobs\Services\QueuedJobService->getNextPendingJob('1')
#12 /home/travis/build/silverstripe/silverstripe-staticpublishqueue/vendor/symbiote/silverstripe-queuedjobs/src/Services/QueuedJobService.php(1390): Symbiote\QueuedJobs\Services\QueuedJobService->processJobQueue('1')
#13 [internal function]: Symbiote\QueuedJobs\Services\QueuedJobService->onShutdown()
#14 {main}PHP Warning:  Invalid argument supplied for foreach() in /home/travis/build/silverstripe/silverstripe-staticpublishqueue/vendor/silverstripe/framework/src/ORM/DataList.php on line 933

Looks like despite my best effort to disable the Symbiote\QueuedJobs\Services\QueuedJobService->onShutdown() it's still being called. The cause for this is that there are some places where QueuedJobService is created via Injector which is not covered by the unit tests customisation. Just having this service is memory is enough to trigger the error as that is the default behaviour.

I was able to resolve this by forced injection approach.