Skip to content

Commit 382a325

Browse files
committed
consider if a library is disabled when checking external library
1 parent 4c164af commit 382a325

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

Symfony/src/Codebender/LibraryBundle/Handler/ApiCommand/FetchApiCommand.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ class FetchApiCommand extends AbstractApiCommand
99
public function execute($content)
1010
{
1111
$content = $this->setDefault($content);
12+
$filename = $content['library'];
13+
14+
$last_slash = strrpos($content['library'], "/");
15+
if ($last_slash !== false) {
16+
$filename = substr($content['library'], $last_slash + 1);
17+
}
1218

1319
$apiHandler = $this->container->get('codebender_library.apiHandler');
1420

@@ -18,13 +24,6 @@ public function execute($content)
1824
$finder = new Finder();
1925
$exampleFinder = new Finder();
2026

21-
$filename = $content['library'];
22-
23-
$last_slash = strrpos($content['library'], "/");
24-
if ($last_slash !== false) {
25-
$filename = substr($content['library'], $last_slash + 1);
26-
}
27-
2827
//TODO handle the case of different .h filenames and folder names
2928
$reservedNames = ["ArduinoRobot" => "Robot_Control", "ArduinoRobotMotorBoard" => "Robot_Motor",
3029
"BlynkSimpleSerial" => "BlynkSimpleEthernet", "BlynkSimpleCC3000" => "BlynkSimpleEthernet"];
@@ -40,7 +39,7 @@ public function execute($content)
4039
$meta = [];
4140
}
4241
} else {
43-
if (!$apiHandler->isExternalLibrary($filename)) {
42+
if (!$apiHandler->isExternalLibrary($filename, $content['disabled'])) {
4443
return ["success" => false, "message" => "No Library named " . $filename . " found."];
4544
}
4645

@@ -74,6 +73,7 @@ public function execute($content)
7473

7574
private function setDefault($content)
7675
{
76+
$content['disabled'] = (array_key_exists('disabled', $content) ? $content['disabled'] : false);
7777
$content['version'] = (array_key_exists('version', $content) ? $content['version'] : null);
7878
$content['renderView'] = (array_key_exists('renderView', $content) ? $content['renderView'] : false);
7979
return $content;

Symfony/src/Codebender/LibraryBundle/Handler/ApiHandler.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,11 +137,14 @@ public function isBuiltInLibraryExample($defaultHeader)
137137
* This method checks if a given external library exists in the database.
138138
*
139139
* @param $defaultHeader
140+
* @param bool $getDisabled
140141
* @return bool
141142
*/
142-
public function isExternalLibrary($defaultHeader)
143+
public function isExternalLibrary($defaultHeader, $getDisabled = false)
143144
{
144-
return $this->getLibraryFromDefaultHeader($defaultHeader) !== null;
145+
$library = $this->getLibraryFromDefaultHeader($defaultHeader);
146+
147+
return $getDisabled ? $library !== null : $library !== null && $library->getActive();
145148
}
146149

147150
/**

0 commit comments

Comments
 (0)