Browse Source

Always uses the primary connection when determining the last entry revision number

#7598
pull/7664/head
brandonkelly 4 years ago
parent
commit
7534da566b
  1. 1
      CHANGELOG.md
  2. 30
      src/services/Revisions.php

1
CHANGELOG.md

@ -16,6 +16,7 @@
- Fixed a bug where Craft wasn’t updating the prior primary site’s project config when a new site was set as the primary in the control panel. ([#7657](https://github.com/craftcms/cms/issues/7657)) - Fixed a bug where Craft wasn’t updating the prior primary site’s project config when a new site was set as the primary in the control panel. ([#7657](https://github.com/craftcms/cms/issues/7657))
- Fixed a bug where the `project-config/apply` command output didn’t make any sense at times. - Fixed a bug where the `project-config/apply` command output didn’t make any sense at times.
- Fixed a race condition where the same queue job could get executed multiple times if there was more than one active queue worker and the database used read/write splitting. - Fixed a race condition where the same queue job could get executed multiple times if there was more than one active queue worker and the database used read/write splitting.
- Fixed a race condition that could result in a SQL error if two revisions were attempted to be created for the same entry at the same time if the database used read/write splitting. ([#7598](https://github.com/craftcms/cms/issues/7598))
## 3.6.9 - 2021-03-05 ## 3.6.9 - 2021-03-05

30
src/services/Revisions.php

@ -84,23 +84,27 @@ class Revisions extends Component
if (!$force || !$num) { if (!$force || !$num) {
// Find the source's last revision number, if it has one // Find the source's last revision number, if it has one
$lastRevisionNum = (new Query())
->select(['num'])
->from([Table::REVISIONS])
->where(['sourceId' => $source->id])
->orderBy(['num' => SORT_DESC])
->limit(1)
->scalar();
$lastRevisionNum = $db->usePrimary(function() use ($source) {
return (new Query())
->select(['num'])
->from([Table::REVISIONS])
->where(['sourceId' => $source->id])
->orderBy(['num' => SORT_DESC])
->limit(1)
->scalar();
});
if (!$force && $lastRevisionNum) { if (!$force && $lastRevisionNum) {
// Get the revision, if it exists for the source's site // Get the revision, if it exists for the source's site
/** @var ElementInterface|RevisionBehavior|null $lastRevision */ /** @var ElementInterface|RevisionBehavior|null $lastRevision */
$lastRevision = $source::find()
->revisionOf($source)
->siteId($source->siteId)
->anyStatus()
->andWhere(['revisions.num' => $lastRevisionNum])
->one();
$lastRevision = $db->usePrimary(function() use ($source, $lastRevisionNum) {
return $source::find()
->revisionOf($source)
->siteId($source->siteId)
->anyStatus()
->andWhere(['revisions.num' => $lastRevisionNum])
->one();
});
// If the source hasn't been updated since the revision's creation date, // If the source hasn't been updated since the revision's creation date,
// there's no need to create a new one // there's no need to create a new one

Loading…
Cancel
Save