<?php
$_db_migration_to = '28.09'; // 8.2.4
if (!isset($migrations) || !is_object($migrations))
	die("This file cannot be executed directly");
$migrations->CheckValid($_db_migration_to);
//===========================================================================================



$migrations->Run('01_add_cdn_mirror_ic_field.php', <<<'DB_UPDATE_FILE'
<?php
/** @var \Claromentis\Setup\SetupFacade $migrations */
$new_dir = $migrations->GetDataDir().'/cdn_mirror/infocapture/field/';

// Create $new_dir path with 0777 permissions
if (!is_dir($new_dir))
	mkdir($new_dir, 0777, true);

$wrong_dir = $migrations->GetDataDir().'/data';
if (is_dir($wrong_dir))
{
	if (count(glob($wrong_dir.'/*')) == 1 &&
		count(glob($wrong_dir.'/cdn_mirror/*')) == 1 &&
		count(glob($wrong_dir.'/cdn_mirror/infocapture/*')) == 1 &&
		count(glob($wrong_dir.'/cdn_mirror/infocapture/field/*')) == 0)
	{
		$migrations->Log("Removing $wrong_dir");
		@rmdir($wrong_dir.'/cdn_mirror/infocapture/field');
		@rmdir($wrong_dir.'/cdn_mirror/infocapture');
		@rmdir($wrong_dir.'/cdn_mirror');
		@rmdir($wrong_dir);
	}
}
DB_UPDATE_FILE
);


//===========================================================================================
$migrations->SetVersion('28.09');
