Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure volumes delete their associated field layouts when deleted. #3022

Merged
merged 1 commit into from
Jun 25, 2018
Merged

Ensure volumes delete their associated field layouts when deleted. #3022

merged 1 commit into from
Jun 25, 2018

Conversation

sbossarte
Copy link
Contributor

Issue

It seems after deleting a volume, its associated fieldlayout remains in the database. This occurs both with manual creation and deletion, as well as programmatically.

Example test code

echo 'Creating volume' . "\n";

$volume = \Craft::$app->getVolumes()->createVolume([
	'type' => \craft\volumes\Local::class,
	'name' => 'Test Assets',
	'handle' => 'testAssets',
	'hasUrls' => true,
	'url' => '@web/test-assets',
	'settings' => [
		'path' => '@webroot/test-assets'
	]
]);
$fieldlayout = new \craft\models\FieldLayout([
	'type' => \craft\elements\Asset::class,
]);
$volume->setFieldLayout($fieldlayout);
if (!\Craft::$app->getVolumes()->saveVolume($volume)) {
	throw new \Exception('Failed to create volume!');
}

$volumeId = $volume->id;
$fieldlayoutId = $fieldlayout->id;

echo 'Volume has ID: ' . $volumeId . "\n";
echo 'Volume field layout has ID: ' . $fieldlayoutId . "\n";

echo 'Deleting volume' . "\n";
\Craft::$app->getVolumes()->deleteVolume($volume);

echo 'Does volume still exist? ' . (\craft\records\Volume::find()->where(['id' => $volumeId])->count() ? 'yes' : 'no') . "\n";
echo 'Does field layout still exist? ' . (\craft\records\FieldLayout::find()->where(['id' => $fieldlayoutId])->count() ? 'yes' : 'no') . "\n";

@brandonkelly brandonkelly merged commit 554aecb into craftcms:develop Jun 25, 2018
@brandonkelly
Copy link
Member

Thank you!

brandonkelly added a commit that referenced this pull request Jun 25, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants