Skip to content

Commit

Permalink
Fixed 2nd deletion Action size
Browse files Browse the repository at this point in the history
Moved code to DeletionHandler Service
  • Loading branch information
tzikis committed Jan 9, 2015
1 parent d42172c commit af91913
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -102,39 +102,13 @@ public function deleteSpecificObjectsAction($auth_key, $version, $option, $to_de
if ($version != "v1")
return new Response(json_encode(array("success" => false, "step" => 0, "message" => "Invalid API version.")));

$tempDir = $this->container->getParameter('temp_dir');
$objectFilesDir = $this->container->getParameter('objdir');

if ($option == "core")
$to_delete = str_replace(":", "_", $to_delete);

$response = array();
$response["deleted_files"] = "";
$response["undeleted_files"] = "";

if ($handle = opendir("$tempDir/$objectFilesDir"))
{
while (false !== ($entry = readdir($handle)))
{
if ($entry == "." || $entry == ".." || $entry == ".DS_Store")
continue;

if ($option == "library" && strpos($entry, "______".$to_delete."_______") === false)
continue;

if ($option == "core" && strpos($entry, "_".$to_delete."_") === false)
continue;

//Get the compiler service
/** @var DeletionHandler $deleter */
$deleter = $this->get('deletion_handler');

if (@unlink("$tempDir/$objectFilesDir/$entry") === false)
$response["undeleted_files"] .= $entry."\n";
else
$response["deleted_files"] .= $entry."\n";
$deleter->deleteSpecificObjects($success, $response, $option, $to_delete);

}
closedir($handle);
}
else
if ($success === false)
{
return new Response(json_encode(array("success" => false, "step" => 0, "message" => "Failed to access object files directory.")));
}
Expand Down
36 changes: 36 additions & 0 deletions Symfony/src/Codebender/CompilerBundle/Handler/DeletionHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,40 @@ function deleteAllObjects(&$success, &$fileCount, &$deletionStats, &$undeletedFi
closedir($handle);
}
}

function deleteSpecificObjects(&$success, &$response, &$option, &$to_delete)
{
if ($option == "core")
$to_delete = str_replace(":", "_", $to_delete);

$success = true;
$response = array();
$response["deleted_files"] = "";
$response["undeleted_files"] = "";

if ($handle = opendir($this->object_directory))
{
while (false !== ($entry = readdir($handle)))
{
if ($entry == "." || $entry == ".." || $entry == ".DS_Store")
continue;

if ($option == "library" && strpos($entry, "______".$to_delete."_______") === false)
continue;

if ($option == "core" && strpos($entry, "_".$to_delete."_") === false)
continue;


if (@unlink($this->object_directory."/$entry") === false)
$response["undeleted_files"] .= $entry."\n";
else
$response["deleted_files"] .= $entry."\n";

}
closedir($handle);
}
else
$success = false;
}
}

0 comments on commit af91913

Please sign in to comment.