Skip to content
This repository was archived by the owner on Sep 10, 2021. It is now read-only.

Commit 9a3d215

Browse files
author
Michael Grauer
committed
STYLE: Refs #209 Changed code to pass style tests.
1 parent c9d48bc commit 9a3d215

File tree

4 files changed

+168
-85
lines changed

4 files changed

+168
-85
lines changed

modules/batchmake/controllers/ConfigController.php

Lines changed: 40 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -47,25 +47,25 @@ class Batchmake_ConfigController extends Batchmake_AppController
4747

4848

4949

50-
public $_moduleForms=array('Config');
51-
public $_components=array('Utility','Internationalization');
52-
public $_moduleComponents=array('KWBatchmake');
50+
public $_moduleForms = array('Config');
51+
public $_components = array('Utility', 'Internationalization');
52+
public $_moduleComponents = array('KWBatchmake');
5353

5454

5555
/**
56-
* @method _archiveOldModuleLocal()
56+
* @method archiveOldModuleLocal()
5757
* will archive the current module.local config file
5858
* written in the hope of being reusable
5959
*/
60-
function _archiveOldModuleLocal()
60+
protected function archiveOldModuleLocal()
6161
{
6262
if(file_exists(BATCHMAKE_MODULE_LOCAL_OLD_CONFIG))
6363
{
6464
unlink(BATCHMAKE_MODULE_LOCAL_OLD_CONFIG);
6565
}
6666
if(file_exists(BATCHMAKE_MODULE_LOCAL_CONFIG))
6767
{
68-
rename(BATCHMAKE_MODULE_LOCAL_CONFIG,BATCHMAKE_MODULE_LOCAL_OLD_CONFIG);
68+
rename(BATCHMAKE_MODULE_LOCAL_CONFIG, BATCHMAKE_MODULE_LOCAL_OLD_CONFIG);
6969
}
7070
}
7171

@@ -74,15 +74,15 @@ function _archiveOldModuleLocal()
7474
/**
7575
* @method indexAction()
7676
*/
77-
function indexAction()
77+
function indexAction()
7878
{
7979

80-
$applicationConfig = $this->ModuleComponent->KWBatchmake->LoadApplicationConfig();
81-
$configPropertiesRequirements = $this->ModuleComponent->KWBatchmake->GetConfigPropertiesRequirements();
80+
$applicationConfig = $this->ModuleComponent->KWBatchmake->loadApplicationConfig();
81+
$configPropertiesRequirements = $this->ModuleComponent->KWBatchmake->getConfigPropertiesRequirements();
8282

8383
$configForm = $this->ModuleForm->Config->createConfigForm($configPropertiesRequirements);
8484
$formArray = $this->getFormAsArray($configForm);
85-
foreach($configPropertiesRequirements as $configProperty=>$configPropertyRequirement)
85+
foreach($configPropertiesRequirements as $configProperty => $configPropertyRequirement)
8686
{
8787
$formArray[$configProperty]->setValue($applicationConfig[GLOBAL_CONFIG_NAME][$this->moduleName.'.'.$configProperty]);
8888
}
@@ -96,8 +96,8 @@ function indexAction()
9696

9797
if(isset($submitConfig))
9898
{
99-
$this->_archiveOldModuleLocal();
100-
foreach($configPropertiesRequirements as $configProperty=>$configPropertyRequirement)
99+
$this->archiveOldModuleLocal();
100+
foreach($configPropertiesRequirements as $configProperty => $configPropertyRequirement)
101101
{
102102
$applicationConfig[GLOBAL_CONFIG_NAME][$this->moduleName.'.'.$configProperty] = $this->_getParam($configProperty);
103103
}
@@ -110,11 +110,11 @@ function indexAction()
110110
}
111111

112112

113-
/**
114-
* @method _testconfig()
113+
/**
114+
* @method testconfig()
115115
* performs validation on the current configuration set through the UI
116116
*/
117-
function _testconfig()
117+
protected function testconfig()
118118
{
119119

120120
//default of correct config
@@ -124,16 +124,19 @@ function _testconfig()
124124

125125

126126
$configPropertiesRequirements = $this->ModuleComponent->KWBatchmake->GetConfigPropertiesRequirements();
127-
foreach($configPropertiesRequirements as $configProperty=>$configPropertyRequirement)
127+
foreach($configPropertiesRequirements as $configProperty => $configPropertyRequirement)
128128
{
129129
$configPropertyVal = $this->_getParam($configProperty);
130130
if($configPropertyVal)
131131
{
132132
// if the property exists, check its configuration
133-
list($result, $status) = $this->ModuleComponent->KWBatchmake->CheckFileFlag( $configPropertyVal, $configPropertyRequirement);
134-
$configStatus[] = array(PROPERTY_KEY => $configProperty, STATUS_KEY => $status, TYPE_KEY => $result?STATUS_TYPE_INFO:STATUS_TYPE_ERROR);
133+
list($result, $status) = $this->ModuleComponent->KWBatchmake->CheckFileFlag($configPropertyVal, $configPropertyRequirement);
134+
$configStatus[] = array(PROPERTY_KEY => $configProperty, STATUS_KEY => $status, TYPE_KEY => $result ? STATUS_TYPE_INFO : STATUS_TYPE_ERROR);
135135
// the property is in error, therefore so is the global config
136-
if(!$result) $total_config_correct = 0;
136+
if(!$result)
137+
{
138+
$total_config_correct = 0;
139+
}
137140
}
138141
else
139142
{
@@ -146,21 +149,24 @@ function _testconfig()
146149
// for now assuming will run via condor, so require all of the condor setup
147150

148151
$appsPaths = $this->ModuleComponent->KWBatchmake->GetApplicationsPaths();
149-
foreach($appsPaths as $app=>$pathProperty)
152+
foreach($appsPaths as $app => $pathProperty)
150153
{
151-
$appPath = $this->_getParam($pathProperty) ."/" . $this->ModuleComponent->KWBatchmake->FormatAppName( $app );
152-
list($result, $status) = $this->ModuleComponent->KWBatchmake->CheckFileFlag( $appPath, CHECK_IF_EXECUTABLE);
154+
$appPath = $this->_getParam($pathProperty) ."/" . $this->ModuleComponent->KWBatchmake->FormatAppName($app);
155+
list($result, $status) = $this->ModuleComponent->KWBatchmake->CheckFileFlag($appPath, CHECK_IF_EXECUTABLE);
153156
$applicationString = $this->Component->Internationalization->translate(APPLICATION_STRING);
154-
$configStatus[] = array(PROPERTY_KEY => $applicationString . ' ' .$appPath, STATUS_KEY => $status, TYPE_KEY => $result?STATUS_TYPE_INFO:STATUS_TYPE_ERROR);
157+
$configStatus[] = array(PROPERTY_KEY => $applicationString . ' ' .$appPath, STATUS_KEY => $status, TYPE_KEY => $result ? STATUS_TYPE_INFO : STATUS_TYPE_ERROR);
155158
// the property is in error, therefore so is the global config
156-
if(!$result) $total_config_correct = 0;
159+
if(!$result)
160+
{
161+
$total_config_correct = 0;
162+
}
157163
}
158164

159165
// Process web server user information
160166

161167
// TODO what should be done if there are warnings??
162-
$processUser = posix_getpwuid( posix_geteuid() );
163-
$processGroup = posix_getgrgid( posix_geteuid() );
168+
$processUser = posix_getpwuid(posix_geteuid());
169+
$processGroup = posix_getgrgid(posix_geteuid());
164170

165171
$phpProcessString = $this->Component->Internationalization->translate(PHP_PROCESS_STRING);
166172
$phpProcessUserString = $phpProcessString . ' ' . $this->Component->Internationalization->translate(PHP_PROCESS_USER_STRING);
@@ -176,16 +182,16 @@ function _testconfig()
176182
$phpProcessUserShellString = $phpProcessUserString . '[' . $phpProcessShellString . ']';
177183

178184
$processProperties = array($phpProcessUserNameString => !empty($processUser[PHP_PROCESS_NAME_STRING]) ? $processUser[PHP_PROCESS_NAME_STRING] : "",
179-
$phpProcessUserGroupString => !empty($processGroup[PHP_PROCESS_NAME_STRING]) ? $processGroup[PHP_PROCESS_NAME_STRING] : "",
180-
$phpProcessUserHomeString => !empty($processUser[DIR_KEY]) ? $processUser[DIR_KEY] : "",
181-
$phpProcessUserShellString => !empty($processUser[PHP_PROCESS_SHELL_STRING]) ? $processUser[PHP_PROCESS_SHELL_STRING] : "");
185+
$phpProcessUserGroupString => !empty($processGroup[PHP_PROCESS_NAME_STRING]) ? $processGroup[PHP_PROCESS_NAME_STRING] : "",
186+
$phpProcessUserHomeString => !empty($processUser[DIR_KEY]) ? $processUser[DIR_KEY] : "",
187+
$phpProcessUserShellString => !empty($processUser[PHP_PROCESS_SHELL_STRING]) ? $processUser[PHP_PROCESS_SHELL_STRING] : "");
182188

183-
foreach($processProperties as $property=>$value)
189+
foreach($processProperties as $property => $value)
184190
{
185191
$status = !empty($value);
186192
$configStatus[] = array(PROPERTY_KEY => $property,
187-
STATUS_KEY => $status ? $value : $unknownString,
188-
TYPE_KEY=> $status?STATUS_TYPE_INFO:STATUS_TYPE_WARNING);
193+
STATUS_KEY => $status ? $value : $unknownString,
194+
TYPE_KEY => $status ? STATUS_TYPE_INFO : STATUS_TYPE_WARNING);
189195
}
190196

191197

@@ -194,7 +200,7 @@ function _testconfig()
194200
}
195201

196202

197-
/**
203+
/**
198204
* @method testconfigAction()
199205
* ajax function which tests config setup, performing
200206
* validation on the current configuration set through the UI
@@ -209,7 +215,7 @@ public function testconfigAction()
209215
$this->_helper->layout->disableLayout();
210216
$this->_helper->viewRenderer->setNoRender();
211217

212-
$config_status = $this->_testconfig();
218+
$config_status = $this->testconfig();
213219
echo JsonComponent::encode($config_status);
214220
}//end testconfigAction
215221

modules/batchmake/controllers/components/KWBatchmakeComponent.php

Lines changed: 82 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -10,43 +10,54 @@
1010
PURPOSE. See the above copyright notices for more information.
1111
=========================================================================*/
1212

13+
/**
14+
* Batchmake_KWBatchmakeComponent
15+
* provides utility methods needed to interact with Batchmake via Midas3.
16+
*/
1317
class Batchmake_KWBatchmakeComponent extends AppComponent
1418
{
1519

16-
// TODO add function level comments
1720

1821
protected $configPropertiesRequirements = array(TMP_DIR_PROPERTY => CHECK_IF_CHMODABLE_RW,
19-
BIN_DIR_PROPERTY => CHECK_IF_READABLE,
20-
SCRIPT_DIR_PROPERTY => CHECK_IF_READABLE,
21-
APP_DIR_PROPERTY => CHECK_IF_READABLE,
22-
DATA_DIR_PROPERTY => CHECK_IF_CHMODABLE_RW,
23-
CONDOR_BIN_DIR_PROPERTY => CHECK_IF_READABLE);
22+
BIN_DIR_PROPERTY => CHECK_IF_READABLE,
23+
SCRIPT_DIR_PROPERTY => CHECK_IF_READABLE,
24+
APP_DIR_PROPERTY => CHECK_IF_READABLE,
25+
DATA_DIR_PROPERTY => CHECK_IF_CHMODABLE_RW,
26+
CONDOR_BIN_DIR_PROPERTY => CHECK_IF_READABLE);
2427

2528
protected $applicationsPaths = array(CONDOR_STATUS => CONDOR_BIN_DIR_PROPERTY,
26-
CONDOR_QUEUE => CONDOR_BIN_DIR_PROPERTY,
27-
CONDOR_SUBMIT => CONDOR_BIN_DIR_PROPERTY,
28-
CONDOR_SUBMIT_DAG => CONDOR_BIN_DIR_PROPERTY,
29-
BATCHMAKE_EXE => BIN_DIR_PROPERTY);
29+
CONDOR_QUEUE => CONDOR_BIN_DIR_PROPERTY,
30+
CONDOR_SUBMIT => CONDOR_BIN_DIR_PROPERTY,
31+
CONDOR_SUBMIT_DAG => CONDOR_BIN_DIR_PROPERTY,
32+
BATCHMAKE_EXE => BIN_DIR_PROPERTY);
3033

3134

3235

3336

34-
public function GetConfigPropertiesRequirements()
35-
{
36-
return $this->configPropertiesRequirements;
37-
}
37+
/**
38+
* @method getConfigPropertiesRequirements()
39+
* accessor method for set of config properties and their requirements.
40+
*/
41+
public function getConfigPropertiesRequirements()
42+
{
43+
return $this->configPropertiesRequirements;
44+
}
3845

39-
public function GetApplicationsPaths()
40-
{
41-
return $this->applicationsPaths;
42-
}
46+
/**
47+
* @method getApplicationsPaths()
48+
* accessor method for set of application paths needed by batchmake module.
49+
*/
50+
public function getApplicationsPaths()
51+
{
52+
return $this->applicationsPaths;
53+
}
4354

4455

4556
/**
46-
* @method LoadApplicationConfig()
57+
* @method loadApplicationConfig()
4758
* written in the hope of being reusable
4859
*/
49-
function LoadApplicationConfig()
60+
function loadApplicationConfig()
5061
{
5162
if(file_exists(BATCHMAKE_MODULE_LOCAL_CONFIG))
5263
{
@@ -62,80 +73,100 @@ function LoadApplicationConfig()
6273

6374

6475

65-
public function CheckFileFlag($file, $options = 0x0)
76+
/**
77+
* @method checkFileFlag()
78+
* checks whether the file at the passed in path has the passed in options.
79+
*/
80+
public function checkFileFlag($file, $options = 0x0)
6681
{
6782
$exist = file_exists($file);
68-
Zend_Loader::loadClass("InternationalizationComponent",BASE_PATH.'/core/controllers/components');
83+
Zend_Loader::loadClass("InternationalizationComponent", BASE_PATH.'/core/controllers/components');
6984
$status = ($exist ? InternationalizationComponent::translate(EXIST_STRING) : InternationalizationComponent::translate(NOT_FOUND_ON_CURRENT_SYSTEM_STRING));
7085
$ret = $exist;
7186

72-
if ( $exist && ($options & CHECK_IF_READABLE) )
87+
if($exist && ($options & CHECK_IF_READABLE))
7388
{
7489
$readable = is_readable($file);
75-
$status.= $readable ? " / Readable" : " / NotReadable";
90+
$status .= $readable ? " / Readable" : " / NotReadable";
7691
$ret = $ret && $readable;
7792
}
7893

79-
if ( $exist && ($options & CHECK_IF_WRITABLE) )
94+
if($exist && ($options & CHECK_IF_WRITABLE))
8095
{
8196
$writable = is_writable($file);
82-
$status.= $writable ? " / Writable" : " / NotWritable";
97+
$status .= $writable ? " / Writable" : " / NotWritable";
8398
$ret = $ret && $writable;
8499
}
85-
if ( $exist && ($options & CHECK_IF_EXECUTABLE) )
100+
if($exist && ($options & CHECK_IF_EXECUTABLE))
86101
{
87102
$executable = is_executable($file);
88-
$status.= $executable ? " / Executable" : " / NotExecutable";
103+
$status .= $executable ? " / Executable" : " / NotExecutable";
89104
$ret = $ret && $executable;
90105
}
91-
if ( !$this->IsWindows() && $exist && ($options & CHECK_IF_CHMODABLE) )
106+
if(!$this->IsWindows() && $exist && ($options & CHECK_IF_CHMODABLE))
92107
{
93108
$chmodable = $this->IsChmodable($file);
94-
$status.= $chmodable ? " / Chmodable" : " / NotChmodable";
109+
$status .= $chmodable ? " / Chmodable" : " / NotChmodable";
95110
$ret = $ret && $chmodable;
96111
}
97112
return array($ret, $status);
98113
}
99114

100115

101-
// STUFF FROM KWUTILS, where should it go?
102116

103-
/** Return True if the current platform is windows */
104-
function IsWindows()
117+
/**
118+
* @method isWindows()
119+
* from KWUtils, may need to be moved.
120+
* @return True if the current platform is windows
121+
*/
122+
function isWindows()
105123
{
106-
return (strtolower( substr(PHP_OS,0,3) ) == "win");
124+
return (strtolower(substr(PHP_OS, 0, 3)) == "win");
107125
}
108126

109-
/** Return True if the current platform is linux */
110-
function IsLinux()
127+
/**
128+
* @method isLinux()
129+
* from KWUtils, may need to be moved.
130+
* @return True if the current platform is Linux
131+
*/
132+
function isLinux()
111133
{
112-
return (strtolower( substr(PHP_OS,0,5) ) == "linux");
134+
return (strtolower(substr(PHP_OS, 0, 5)) == "linux");
113135
}
114136

115-
/** Format the application name according to the plateform */
116-
function FormatAppName( $app_name )
137+
/**
138+
* @method formatAppName
139+
* from KWUtils, may need to be moved.
140+
* Format the application name according to the platform.
141+
*/
142+
function formatAppName($app_name)
117143
{
118-
if (substr(PHP_OS,0,3) == "WIN")
144+
if(substr(PHP_OS, 0, 3) == "WIN")
119145
{
120-
$app_name = self::AppendStringIfNot($app_name,".exe");
146+
$app_name = self::AppendStringIfNot($app_name, ".exe");
121147
}
122148
return $app_name;
123149
}
124150

125151
/**
152+
* @method isChmodable
126153
* Check if current PHP process has permission to change the mode
127154
* of $fileOrDirectory.
155+
* from KWUtils, may need to be moved.
128156
* Note: If return true, the mode of the file will be DEFAULT_MKDIR_MODE
129157
* On windows, return always True
130158
*/
131-
function IsChmodable( $fileOrDirectory)
159+
function isChmodable($fileOrDirectory)
132160
{
133-
if ($this->IsWindows()) { return true; }
161+
if($this->isWindows())
162+
{
163+
return true;
164+
}
134165

135-
if ( !file_exists($fileOrDirectory) )
166+
if(!file_exists($fileOrDirectory))
136167
{
137-
Zend_Loader::loadClass("InternationalizationComponent",BASE_PATH.'/core/controllers/components');
138-
self::Error(InternationalizationComponent::translate(FILE_OR_DIRECTORY_DOESNT_EXIST_STRING)." [$fileOrDirectory]");
168+
Zend_Loader::loadClass("InternationalizationComponent", BASE_PATH.'/core/controllers/components');
169+
self::Error(InternationalizationComponent::translate(FILE_OR_DIRECTORY_DOESNT_EXIST_STRING).' ['.$fileOrDirectory.']');
139170
return false;
140171
}
141172

@@ -144,10 +175,13 @@ function IsChmodable( $fileOrDirectory)
144175
//$current_perms = self::GetFilePermissions( $fileOrDirectory );
145176
$current_perms = DEFAULT_MKDIR_MODE;
146177
//self::Debug("File permissions: [file: $fileOrDirectory, mode: ".decoct($current_perms)."]");
147-
if ($current_perms===false){ return false; }
178+
if($current_perms === false)
179+
{
180+
return false;
181+
}
148182

149183
// Try to re-apply them
150-
if (!@chmod($fileOrDirectory, $current_perms))
184+
if(!@chmod($fileOrDirectory, $current_perms))
151185
{
152186
//self::Debug("Failed to change mode: [file: $fileOrDirectory] to [mode: ".decoct($current_perms)."]");
153187
return false;

0 commit comments

Comments
 (0)