Skip to content
Snippets Groups Projects
Unverified Commit 7de8fc1f authored by Alex Pott's avatar Alex Pott
Browse files

Issue #3215836 by guilhermevp, imalabya, swatichouhan012, AJV009, joachim,...

Issue #3215836 by guilhermevp, imalabya, swatichouhan012, AJV009, joachim, quietone: add a constant to represent uncountable sources for SourcePluginBase::count()
parent 69772dbf
Branches
Tags
17 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!1896Issue #2940605: Can only intentionally re-render an entity with references 20 times,!1101Issue #2412669 by claudiu.cristea, Julfabre, sidharrell, catch, daffie,...,!1039Issue #2556069 by claudiu.cristea, bnjmnm, lauriii, pfrenssen, Tim Bozeman,...,!10223132456: Fix issue where views instances are emptied before an ajax request is complete,!1012Issue #3226887: Hreflang on non-canonical content pages,!872Draft: Issue #3221319: Race condition when creating menu links and editing content deletes menu links,!594Put each entity type table into a details element on admin/config/regional/content-language,!579Issue #2230909: Simple decimals fail to pass validation,!560Move callback classRemove outside of the loop,!555Issue #3202493,!512Issue #3207771: Menu UI node type form documentation points to non-existent function,!485Sets the autocomplete attribute for username/password input field on login form.,!449Issue #2784233: Allow multiple vocabularies in the taxonomy filter,!231Issue #2671162: summary text wysiwyg patch working fine on 9.2.0-dev,!43Resolve #3173180: Add UI for 'loading' html attribute to images,!30Issue #3182188: Updates composer usage to point at ./vendor/bin/composer
......@@ -17,6 +17,11 @@
*/
interface MigrateSourceInterface extends \Countable, \Iterator, PluginInspectionInterface {
/**
* Indicates that the source is not countable.
*/
const NOT_COUNTABLE = -1;
/**
* Returns available fields on the source.
*
......
......@@ -85,10 +85,11 @@
* @endcode
*
* In this example, skip_count is true which means count() will not attempt to
* count the available source records, but just always return -1 instead. The
* high_water_property defines which field marks the last imported row of the
* migration. This will get converted into a SQL condition that looks like
* 'n.changed' or 'changed' if no alias.
* count the available source records, but just always return
* MigrateSourceInterface::NOT_COUNTABLE instead. The high_water_property
* defines which field marks the last imported row of the migration. This will
* get converted into a SQL condition that looks like 'n.changed' or 'changed'
* if no alias.
*
* Example:
*
......@@ -473,7 +474,8 @@ public function getCurrentIds() {
* Gets the source count.
*
* Return a count of available source records, from the cache if appropriate.
* Returns -1 if the source is not countable.
* Returns MigrateSourceInterface::NOT_COUNTABLE if the source is not
* countable.
*
* @param bool $refresh
* (optional) Whether or not to refresh the count. Defaults to FALSE. Not
......@@ -486,7 +488,7 @@ public function getCurrentIds() {
*/
public function count($refresh = FALSE) {
if ($this->skipCount) {
return -1;
return MigrateSourceInterface::NOT_COUNTABLE;
}
// Return the cached count if we are caching counts and a refresh is not
......
......@@ -17,6 +17,7 @@
use Drupal\migrate\MigrateSkipRowException;
use Drupal\migrate\Plugin\migrate\source\SourcePluginBase;
use Drupal\migrate\Plugin\MigrateIdMapInterface;
use Drupal\migrate\Plugin\MigrateSourceInterface;
use Drupal\migrate\Row;
/**
......@@ -186,14 +187,14 @@ public function testCount() {
// Test the skip argument.
$source = $this->getSource(['skip_count' => TRUE]);
$this->assertEquals(-1, $source->count());
$this->assertEquals(MigrateSourceInterface::NOT_COUNTABLE, $source->count());
$this->migrationConfiguration['id'] = 'test_migration';
$migration = $this->getMigration();
$source = new StubSourceGeneratorPlugin([], '', [], $migration);
// Test the skipCount property's default value.
$this->assertEquals(-1, $source->count());
$this->assertEquals(MigrateSourceInterface::NOT_COUNTABLE, $source->count());
// Test the count value using a generator.
$source = new StubSourceGeneratorPlugin(['skip_count' => FALSE], '', [], $migration);
......
......@@ -11,6 +11,7 @@
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\migrate\EntityFieldDefinitionTrait;
use Drupal\migrate\Plugin\migrate\source\SourcePluginBase;
use Drupal\migrate\Plugin\MigrateSourceInterface;
use Drupal\migrate\Plugin\MigrationInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
......@@ -248,7 +249,7 @@ public function count($refresh = FALSE) {
}
// @TODO: Determine a better way to retrieve a valid count for translations.
// https://www.drupal.org/project/drupal/issues/2937166
return -1;
return MigrateSourceInterface::NOT_COUNTABLE;
}
/**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment