DisqusCommentsStatus.php in Disqus 8
File
src/Plugin/migrate/source/DisqusCommentsStatus.php
View source
<?php
namespace Drupal\disqus\Plugin\migrate\source;
use Drupal\migrate\Row;
use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
class DisqusCommentsStatus extends DrupalSqlBase {
public function fields() {
return [
'nid' => $this
->t('ID of Node this status belongs to'),
'status' => $this
->t('Disqus comments status'),
'identifier' => $this
->t('Disqus thread identifier'),
];
}
protected function getEnabledTypes() {
$enabled = $this
->getDatabase()
->select('variable', 'v')
->fields('v', [
'value',
])
->condition('v.name', 'disqus_nodetypes')
->execute()
->fetchField();
return array_filter(unserialize($enabled));
}
public function query() {
$query = $this
->select('node', 'n');
$query
->condition('n.type', $this
->getEnabledTypes(), 'IN');
$query
->orderBy('n.nid');
$query
->leftJoin('disqus', 'd', 'd.nid=n.nid');
$query
->addField('n', 'nid', 'nid');
$query
->addExpression('IF(d.status IS NULL, 1, d.status)', 'status');
return $query;
}
public function count($refresh = FALSE) {
return $this
->getDatabase()
->select('node', 'n')
->condition('n.type', $this
->getEnabledTypes(), 'IN')
->countQuery()
->execute()
->fetchField();
}
public function prepareRow(Row $row) {
parent::prepareRow($row);
$nid = $row
->getSourceProperty('nid');
$row
->setSourceProperty('identifier', 'node/' . $nid);
}
public function getIds() {
$ids['nid']['type'] = 'integer';
$ids['nid']['alias'] = 'n';
return $ids;
}
}