Last active
December 2, 2015 19:18
-
-
Save e0ipso/6592130d3d0e900d3a72 to your computer and use it in GitHub Desktop.
EntityFieldQuery IS NULL
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$bundle = 'article'; | |
$entity_type = 'node'; | |
$field = 'body'; | |
$column = 'value'; | |
print init_query($entity_type, $bundle) | |
->count() | |
->execute() . ' entities.' . PHP_EOL; | |
$bodyless = init_query($entity_type, $bundle) | |
->fieldCondition($field, $column, NULL, 'IS NULL') | |
->count() | |
->execute(); | |
print $bodyless . ' IS NULL entities.' . PHP_EOL; | |
$bodied = init_query($entity_type, $bundle) | |
->fieldCondition($field, $column, TRUE, 'IS NOT NULL') | |
->count() | |
->execute(); | |
print $bodied . ' IS NOT NULL entities.' . PHP_EOL; | |
print sprintf('(%d + %d) = %d', $bodyless, $bodied, $bodyless + $bodied) . PHP_EOL; | |
/** | |
* Generate an Entity Field Query. | |
*/ | |
function init_query($entity_type, $bundle) { | |
$query = new \Drupal\restful\Util\EntityFieldQuery(); | |
$query->entityCondition('entity_type', $entity_type) | |
->entityCondition('bundle', $bundle); | |
return $query; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-------------------------------------------- | |
➜ drush scr /var/www/custom-scripts/efq.php | |
-------------------------------------------- | |
48327 entities. | |
536 IS NULL entities. | |
47791 IS NOT NULL entities. | |
(536 + 47791) = 48327 | |
-------------------------------------------- |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment