Skip to content

Commit af91913

Browse files
committed
Fixed 2nd deletion Action size
Moved code to DeletionHandler Service
1 parent d42172c commit af91913

File tree

2 files changed

+41
-31
lines changed

2 files changed

+41
-31
lines changed

Symfony/src/Codebender/CompilerBundle/Controller/DefaultController.php

Lines changed: 5 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -102,39 +102,13 @@ public function deleteSpecificObjectsAction($auth_key, $version, $option, $to_de
102102
if ($version != "v1")
103103
return new Response(json_encode(array("success" => false, "step" => 0, "message" => "Invalid API version.")));
104104

105-
$tempDir = $this->container->getParameter('temp_dir');
106-
$objectFilesDir = $this->container->getParameter('objdir');
107-
108-
if ($option == "core")
109-
$to_delete = str_replace(":", "_", $to_delete);
110-
111-
$response = array();
112-
$response["deleted_files"] = "";
113-
$response["undeleted_files"] = "";
114-
115-
if ($handle = opendir("$tempDir/$objectFilesDir"))
116-
{
117-
while (false !== ($entry = readdir($handle)))
118-
{
119-
if ($entry == "." || $entry == ".." || $entry == ".DS_Store")
120-
continue;
121-
122-
if ($option == "library" && strpos($entry, "______".$to_delete."_______") === false)
123-
continue;
124-
125-
if ($option == "core" && strpos($entry, "_".$to_delete."_") === false)
126-
continue;
127-
105+
//Get the compiler service
106+
/** @var DeletionHandler $deleter */
107+
$deleter = $this->get('deletion_handler');
128108

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

134-
}
135-
closedir($handle);
136-
}
137-
else
111+
if ($success === false)
138112
{
139113
return new Response(json_encode(array("success" => false, "step" => 0, "message" => "Failed to access object files directory.")));
140114
}

Symfony/src/Codebender/CompilerBundle/Handler/DeletionHandler.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,40 @@ function deleteAllObjects(&$success, &$fileCount, &$deletionStats, &$undeletedFi
6969
closedir($handle);
7070
}
7171
}
72+
73+
function deleteSpecificObjects(&$success, &$response, &$option, &$to_delete)
74+
{
75+
if ($option == "core")
76+
$to_delete = str_replace(":", "_", $to_delete);
77+
78+
$success = true;
79+
$response = array();
80+
$response["deleted_files"] = "";
81+
$response["undeleted_files"] = "";
82+
83+
if ($handle = opendir($this->object_directory))
84+
{
85+
while (false !== ($entry = readdir($handle)))
86+
{
87+
if ($entry == "." || $entry == ".." || $entry == ".DS_Store")
88+
continue;
89+
90+
if ($option == "library" && strpos($entry, "______".$to_delete."_______") === false)
91+
continue;
92+
93+
if ($option == "core" && strpos($entry, "_".$to_delete."_") === false)
94+
continue;
95+
96+
97+
if (@unlink($this->object_directory."/$entry") === false)
98+
$response["undeleted_files"] .= $entry."\n";
99+
else
100+
$response["deleted_files"] .= $entry."\n";
101+
102+
}
103+
closedir($handle);
104+
}
105+
else
106+
$success = false;
107+
}
72108
}

0 commit comments

Comments
 (0)