src/Codeception/Module/WPDb.php
public function dontHaveAttachmentFilesInDatabase($attachmentIds)
    {
        $postmeta = $this->grabPostmetaTableName();

        foreach ((array)$attachmentIds as $attachmentId) {
            $attachedFile = $this->grabAttachmentAttachedFile($attachmentId);
            $attachmentMetadata = $this->grabAttachmentMetadata($attachmentId);

            $fs = $this->getWpFilesystemModule();
            $filesPath = Utils::untrailslashit($fs->getUploadsPath(dirname($attachedFile)));

            if (!isset($attachmentMetadata['sizes']) && is_array($attachmentMetadata['sizes'])) {
                continue;
            }

            foreach ($attachmentMetadata['sizes'] as $size => $sizeData) {
                $filePath = $filesPath . '/' . $sizeData['file'];
                $fs->deleteUploadedFile($filePath);
            }
            $fs->deleteUploadedFile($attachedFile);
        }
    }
public function dontHaveAttachmentFilesInDatabase($attachmentIds)
    {
        $postmeta = $this->grabPostmetaTableName();

        foreach ((array)$attachmentIds as $attachmentId) {
            $attachedFile = $this->grabAttachmentAttachedFile($attachmentId);
            $attachmentMetadata = $this->grabAttachmentMetadata($attachmentId);

            $fs = $this->getWpFilesystemModule();
            $filesPath = Utils::untrailslashit($fs->getUploadsPath(dirname($attachedFile)));

            if (!isset($attachmentMetadata['sizes']) && is_array($attachmentMetadata['sizes'])) {
                continue;
            }

            foreach ($attachmentMetadata['sizes'] as $size => $sizeData) {
                $filePath = $filesPath . '/' . $sizeData['file'];
                $fs->deleteUploadedFile($filePath);
            }
            $fs->deleteUploadedFile($attachedFile);
        }
    }
public function dontHaveAttachmentFilesInDatabase ( $ attachmentIds ) { $ postmeta = $ this -> grabPostmetaTableName ( ) ; foreach ( ( array ) $ attachmentIds as $ attachmentId ) { $ attachedFile = $ this -> grabAttachmentAttachedFile ( $ attachmentId ) ; $ attachmentMetadata = $ this -> grabAttachmentMetadata ( $ attachmentId ) ; $ fs = $ this -> getWpFilesystemModule ( ) ; $ filesPath = Utils :: untrailslashit ( $ fs -> getUploadsPath ( dirname ( $ attachedFile ) ) ) ; if ( ! isset ( $ attachmentMetadata [ 'sizes' ] ) && is_array ( $ attachmentMetadata [ 'sizes' ] ) ) { continue ; } foreach ( $ attachmentMetadata [ 'sizes' ] as $ size => $ sizeData ) { $ filePath = $ filesPath . '/' . $ sizeData [ 'file' ] ; $ fs -> deleteUploadedFile ( $ filePath ) ; } $ fs -> deleteUploadedFile ( $ attachedFile ) ; } }
Removes all the files attached with an attachment post, it will not remove the database entries.
Requires the `WPFilesystem` module to be loaded in the suite.

@example
```php
$posts = $I->grabPostsTableName();
$attachmentIds = $I->grabColumnFromDatabase($posts, 'ID', ['post_type' => 'attachment']);
// This will only remove the files, not the database entries.
$I->dontHaveAttachmentFilesInDatabase($attachmentIds);
```

@param array|int $attachmentIds An attachment post ID or an array of attachment post IDs.

@throws \Codeception\Exception\ModuleException If the `WPFilesystem` module is not loaded in the suite.
Removes all the files attached with an attachment post it will not remove the database entries . Requires the WPFilesystem module to be loaded in the suite .