src/Codeception/Module/WPDb.php
public function dontHaveAttachmentInDatabase(array $criteria, $purgeMeta = true, $removeFiles = false)
    {
        $mergedCriteria = array_merge($criteria, ['post_type' => 'attachment']);

        if ((bool)$removeFiles) {
            $posts = $this->grabPostsTableName();
            $attachmentIds = $this->grabColumnFromDatabase($posts, 'ID', $mergedCriteria);
            $this->dontHaveAttachmentFilesInDatabase($attachmentIds);
        }

        $this->dontHavePostInDatabase($mergedCriteria, $purgeMeta);
    }
public function dontHaveAttachmentInDatabase(array $criteria, $purgeMeta = true, $removeFiles = false)
    {
        $mergedCriteria = array_merge($criteria, ['post_type' => 'attachment']);

        if ((bool)$removeFiles) {
            $posts = $this->grabPostsTableName();
            $attachmentIds = $this->grabColumnFromDatabase($posts, 'ID', $mergedCriteria);
            $this->dontHaveAttachmentFilesInDatabase($attachmentIds);
        }

        $this->dontHavePostInDatabase($mergedCriteria, $purgeMeta);
    }
public function dontHaveAttachmentInDatabase ( array $ criteria , $ purgeMeta = true , $ removeFiles = false ) { $ mergedCriteria = array_merge ( $ criteria , [ 'post_type' => 'attachment' ] ) ; if ( ( bool ) $ removeFiles ) { $ posts = $ this -> grabPostsTableName ( ) ; $ attachmentIds = $ this -> grabColumnFromDatabase ( $ posts , 'ID' , $ mergedCriteria ) ; $ this -> dontHaveAttachmentFilesInDatabase ( $ attachmentIds ) ; } $ this -> dontHavePostInDatabase ( $ mergedCriteria , $ purgeMeta ) ; }
Removes an attachment from the posts table.

@example
```
$postmeta = $I->grabpostmetatablename();
$thumbnailId = $I->grabFromDatabase($postmeta, 'meta_value', [
'post_id' => $id,
'meta_key'=>'thumbnail_id'
]);
// Remove only the database entry (including postmeta) but not the files.
$I->dontHaveAttachmentInDatabase($thumbnailId);
// Remove the database entry (including postmeta) and the files.
$I->dontHaveAttachmentInDatabase($thumbnailId, true, true);
```

@param  array $criteria    An array of search criteria to find the attachment post in the posts table.
@param bool   $purgeMeta   If set to `true` then the meta for the attachment will be purged too.
@param bool   $removeFiles Remove all files too, requires the `WPFilesystem` module to be loaded in the suite.

@throws \Codeception\Exception\ModuleException If the WPFilesystem module is not loaded in the suite
and the `$removeFiles` argument is `true`.
Removes an attachment from the posts table .