class CleanState in Feeds 8.3
State for the clean stage.
Hierarchy
- class \Drupal\feeds\State implements StateInterface
- class \Drupal\feeds\Feeds\State\CleanState implements CleanStateInterface uses DependencySerializationTrait
Expanded class hierarchy of CleanState
3 files declare their use of CleanState
- EntityProcessorBaseTest.php in tests/
src/ Kernel/ Feeds/ Processor/ EntityProcessorBaseTest.php - Feed.php in src/
Entity/ Feed.php - FeedRefreshTest.php in tests/
src/ Unit/ Plugin/ QueueWorker/ FeedRefreshTest.php
File
- src/
Feeds/ State/ CleanState.php, line 16
Namespace
Drupal\feeds\Feeds\StateView source
class CleanState extends State implements CleanStateInterface {
use DependencySerializationTrait;
/**
* The database table name.
*/
const TABLE_NAME = 'feeds_clean_list';
/**
* The ID of the feed this state belongs to.
*
* @var int
*/
protected $feedId;
/**
* The database connection.
*
* @var \Drupal\Core\Database\Connection
*/
protected $connection;
/**
* Whether or not the list was initiated or not.
*
* @var bool
*/
protected $initiated = FALSE;
/**
* The type of the entity ID's on the list.
*
* @var string
*/
protected $entityTypeId;
/**
* Constructs a new CleanState.
*
* @param int $feed_id
* The ID of the feed this state belongs to.
* @param \Drupal\Core\Database\Connection $connection
* (optional) The Connection object containing the feeds tables.
*/
public function __construct($feed_id, Connection $connection = NULL) {
$this->feedId = $feed_id;
if (empty($connection)) {
$this->connection = \Drupal::database();
}
else {
$this->connection = $connection;
}
}
/**
* {@inheritdoc}
*/
public function progress($total, $progress) {
if (!$this
->count()) {
$this
->setCompleted();
}
return parent::progress($total, $progress);
}
/**
* {@inheritdoc}
*/
public function initiated() {
return $this->initiated;
}
/**
* {@inheritdoc}
*/
public function setList(array $ids) {
// Remove previous list first.
$this->connection
->delete(static::TABLE_NAME)
->condition('feed_id', $this->feedId)
->execute();
// Insert the list into the database.
if (!empty($ids)) {
$query = $this->connection
->insert(static::TABLE_NAME)
->fields([
'feed_id',
'entity_id',
]);
foreach ($ids as $id) {
$query
->values([
'feed_id' => $this->feedId,
'entity_id' => $id,
]);
}
$query
->execute();
}
// Set flag that initiating is done.
$this->initiated = TRUE;
}
/**
* {@inheritdoc}
*/
public function getList() {
// Get all ID's.
return $this->connection
->select(static::TABLE_NAME)
->fields(static::TABLE_NAME, [
'entity_id',
])
->condition('feed_id', $this->feedId)
->execute()
->fetchCol();
}
/**
* {@inheritdoc}
*/
public function removeItem($entity_id) {
$this->connection
->delete(static::TABLE_NAME)
->condition('feed_id', $this->feedId)
->condition('entity_id', $entity_id)
->execute();
$this->total = $this
->count();
$this
->progress($this->total, $this->updated);
}
/**
* {@inheritdoc}
*/
public function nextEntity(EntityStorageInterface $storage = NULL) {
if (!$this
->initiated()) {
return;
}
$entity_id = $this->connection
->queryRange('SELECT entity_id FROM {' . static::TABLE_NAME . '} WHERE feed_id = :feed_id', 0, 1, [
':feed_id' => $this->feedId,
])
->fetchField();
if (!$entity_id) {
return;
}
// Claim the item, remove it from the list.
$this
->removeItem($entity_id);
if (!$storage) {
$entity_type_id = $this
->getEntityTypeId();
if (!$entity_type_id) {
throw new RuntimeException('The clean state does not have an entity type assigned.');
}
$storage = \Drupal::entityTypeManager()
->getStorage($this
->getEntityTypeId());
}
$entity = $storage
->load($entity_id);
if ($entity instanceof EntityInterface) {
return $entity;
}
else {
return $this
->nextEntity($storage);
}
}
/**
* {@inheritdoc}
*/
public function setEntityTypeId($entity_type_id) {
// @todo check for valid entity type id.
$this->entityTypeId = $entity_type_id;
}
/**
* {@inheritdoc}
*/
public function getEntityTypeId() {
return $this->entityTypeId;
}
/**
* {@inheritdoc}
*/
public function getIterator() {
return new ArrayIterator($this
->getList());
}
/**
* {@inheritdoc}
*/
public function count() {
return (int) $this->connection
->query('SELECT COUNT(feed_id) FROM {' . static::TABLE_NAME . '} WHERE feed_id = :feed_id', [
':feed_id' => $this->feedId,
])
->fetchField();
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
CleanState:: |
protected | property | The database connection. | |
CleanState:: |
protected | property | The type of the entity ID's on the list. | |
CleanState:: |
protected | property | The ID of the feed this state belongs to. | |
CleanState:: |
protected | property | Whether or not the list was initiated or not. | |
CleanState:: |
public | function | ||
CleanState:: |
public | function |
Returns the entity type ID of the entity ID's on the list. Overrides CleanStateInterface:: |
|
CleanState:: |
public | function | ||
CleanState:: |
public | function |
Returns the list of entity ID's. Overrides CleanStateInterface:: |
|
CleanState:: |
public | function |
Returns if the list is initiated. Overrides CleanStateInterface:: |
|
CleanState:: |
public | function |
Returns the next entity in the list and removes the ID from the list. Overrides CleanStateInterface:: |
|
CleanState:: |
public | function |
Reports the progress of a batch. Overrides State:: |
|
CleanState:: |
public | function |
Removes a specific item from the list. Overrides CleanStateInterface:: |
|
CleanState:: |
public | function |
Sets the entity type ID of the entity ID's on the list. Overrides CleanStateInterface:: |
|
CleanState:: |
public | function |
Sets the list of entity ID's. Overrides CleanStateInterface:: |
|
CleanState:: |
constant | The database table name. | ||
CleanState:: |
public | function | Constructs a new CleanState. | |
DependencySerializationTrait:: |
protected | property | An array of entity type IDs keyed by the property name of their storages. | |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | 1 | |
DependencySerializationTrait:: |
public | function | 2 | |
State:: |
public | property | The number of Feed items created. | |
State:: |
public | property | The number of Feed items deleted. | |
State:: |
public | property | The number of failed Feed items. | |
State:: |
protected | property | The list of messages to display to the user. | |
State:: |
public | property | Used as a pointer to store where left off. Must be serializable. | |
State:: |
public | property | Denotes the progress made. | 1 |
State:: |
public | property | The number of Feed items skipped. | |
State:: |
public | property | The total number of items being processed. | |
State:: |
public | property | The number of Feed items updated. | |
State:: |
public | function |
Shows the messages to the user. Overrides StateInterface:: |
|
State:: |
public | function |
Logs all messages. Overrides StateInterface:: |
|
State:: |
public | function |
Immediately completes the batch. Overrides StateInterface:: |
|
State:: |
public | function |
Sets a message to display to the user. Overrides StateInterface:: |
|
StateInterface:: |
constant | Batch operation complete. | ||
StateInterface:: |
constant | Denotes the clean stage. | ||
StateInterface:: |
constant | Denotes the clear stage. | ||
StateInterface:: |
constant | Denotes the expire stage. | ||
StateInterface:: |
constant | Denotes the fetch stage. | ||
StateInterface:: |
constant | Denotes the parse stage. | ||
StateInterface:: |
constant | Denotes the process stage. | ||
StateInterface:: |
constant | The start time key. |