Merge and code standards.

Forgot to clean View/Helper/AppHelper.php.
Changed underscore method names to private and protected where
appropriate given phpcs code standards errors.
pull/61/head
noud 2012-09-24 09:02:09 +02:00
parent 7129bb18a3
commit 8179a1a691
5 changed files with 34 additions and 33 deletions

View File

@ -101,7 +101,7 @@ class AppController extends Controller {
/** /**
* Convert an array to the same array but with the values also as index instead of an interface_exists * Convert an array to the same array but with the values also as index instead of an interface_exists
*/ */
public function _arrayToValuesIndexArray($oldArray) { protected function _arrayToValuesIndexArray($oldArray) {
$newArray = Array(); $newArray = Array();
foreach ($oldArray as $value) foreach ($oldArray as $value)
$newArray[$value] = $value; $newArray[$value] = $value;
@ -111,7 +111,7 @@ class AppController extends Controller {
/** /**
* checks if the currently logged user is an administrator * checks if the currently logged user is an administrator
*/ */
public function _isAdmin() { protected function _isAdmin() {
$org = $this->Auth->user('org'); $org = $this->Auth->user('org');
if (isset($org) && $org === 'ADMIN') { if (isset($org) && $org === 'ADMIN') {
return true; return true;
@ -123,7 +123,7 @@ class AppController extends Controller {
* Refreshes the Auth session with new/updated data * Refreshes the Auth session with new/updated data
* @return void * @return void
*/ */
public function _refreshAuth() { protected function _refreshAuth() {
if (isset($this->User)) { if (isset($this->User)) {
$user = $this->User->read(false, $this->Auth->user('id')); $user = $this->User->read(false, $this->Auth->user('id'));
} else { } else {
@ -182,7 +182,7 @@ class AppController extends Controller {
* Log in as admin user and * Log in as admin user and
* Then run this function by setting debug = 1 (or more) and call /events/migrate02to021 * Then run this function by setting debug = 1 (or more) and call /events/migrate02to021
*/ */
public function _explodeValueToValues() { private function __explodeValueToValues() {
// search for composite value1 fields and explode it to value1 and value2 // search for composite value1 fields and explode it to value1 and value2
$this->loadModel('Attribute'); $this->loadModel('Attribute');
$params = array( $params = array(
@ -215,7 +215,7 @@ class AppController extends Controller {
} }
// search for composite value1 fields and explode it to value1 and value2 // search for composite value1 fields and explode it to value1 and value2
$this->_explodeValueToValues(); $this->__explodeValueToValues();
} }
public function migrate021to022() { public function migrate021to022() {

View File

@ -420,7 +420,7 @@ class AttributesController extends AppController {
// delete the attribute from remote servers // delete the attribute from remote servers
if ('true' == Configure::read('CyDefSIG.sync')) { if ('true' == Configure::read('CyDefSIG.sync')) {
// find the uuid // find the uuid
$this->_deleteAttributeFromServers($uuid); $this->__deleteAttributeFromServers($uuid);
} }
$this->Session->setFlash(__('Attribute deleted')); $this->Session->setFlash(__('Attribute deleted'));
@ -436,7 +436,7 @@ class AttributesController extends AppController {
* Deletes this specific attribute from all remote servers * Deletes this specific attribute from all remote servers
* TODO move this to a component(?) * TODO move this to a component(?)
*/ */
public function _deleteAttributeFromServers($uuid) { private function __deleteAttributeFromServers($uuid) {
$result = $this->Attribute->find('first', array('conditions' => array('Attribute.uuid' => $uuid))); $result = $this->Attribute->find('first', array('conditions' => array('Attribute.uuid' => $uuid)));
$id = $result['Attribute']['id']; $id = $result['Attribute']['id'];

View File

@ -303,9 +303,9 @@ class EventsController extends AppController {
// from the attributes attachments are also saved to the disk thanks to the afterSave() fonction of Attribute // from the attributes attachments are also saved to the disk thanks to the afterSave() fonction of Attribute
if ($this->Event->saveAssociated($data, array('validate' => true, 'fieldList' => $fieldList))) { if ($this->Event->saveAssociated($data, array('validate' => true, 'fieldList' => $fieldList))) {
if (!empty($data['Event']['published']) && 1 == $data['Event']['published']) { if (!empty($data['Event']['published']) && 1 == $data['Event']['published']) {
// call _sendAlertEmail if published was set in the request // call __sendAlertEmail if published was set in the request
if (!$fromXml) { if (!$fromXml) {
$this->_sendAlertEmail($this->Event->getId()); $this->__sendAlertEmail($this->Event->getId());
} }
} }
return true; return true;
@ -420,7 +420,7 @@ class EventsController extends AppController {
// delete the event from remote servers // delete the event from remote servers
if ('true' == Configure::read('CyDefSIG.sync')) { // TODO test..(!$this->_isRest()) && if ('true' == Configure::read('CyDefSIG.sync')) { // TODO test..(!$this->_isRest()) &&
$this->_deleteEventFromServers($uuid); $this->__deleteEventFromServers($uuid);
} }
$this->Session->setFlash(__('Event deleted')); $this->Session->setFlash(__('Event deleted'));
@ -434,7 +434,7 @@ class EventsController extends AppController {
* Uploads this specific event to all remote servers * Uploads this specific event to all remote servers
* TODO move this to a component * TODO move this to a component
*/ */
private function _uploadEventToServers($id) { private function __uploadEventToServers($id) {
// make sure we have all the data of the Event // make sure we have all the data of the Event
$this->Event->id = $id; $this->Event->id = $id;
$this->Event->recursive = 1; $this->Event->recursive = 1;
@ -461,7 +461,7 @@ class EventsController extends AppController {
* Delets this specific event to all remote servers * Delets this specific event to all remote servers
* TODO move this to a component(?) * TODO move this to a component(?)
*/ */
private function _deleteEventFromServers($uuid) { private function __deleteEventFromServers($uuid) {
// get a list of the servers // get a list of the servers
$this->loadModel('Server'); $this->loadModel('Server');
$servers = $this->Server->find('all', array()); $servers = $this->Server->find('all', array());
@ -482,7 +482,7 @@ class EventsController extends AppController {
* *
* @param unknown_type $id * @param unknown_type $id
*/ */
private function _publish($id) { private function __publish($id) {
$this->Event->id = $id; $this->Event->id = $id;
$this->Event->recursive = 0; $this->Event->recursive = 0;
//$this->Event->read(); //$this->Event->read();
@ -492,7 +492,7 @@ class EventsController extends AppController {
// upload the event to remote servers // upload the event to remote servers
if ('true' == Configure::read('CyDefSIG.sync')) if ('true' == Configure::read('CyDefSIG.sync'))
$this->_uploadEventToServers($id); $this->__uploadEventToServers($id);
} }
/** /**
@ -511,7 +511,7 @@ class EventsController extends AppController {
// only allow form submit CSRF protection. // only allow form submit CSRF protection.
if ($this->request->is('post') || $this->request->is('put')) { if ($this->request->is('post') || $this->request->is('put')) {
// Performs all the actions required to publish an event // Performs all the actions required to publish an event
$this->_publish($id); $this->__publish($id);
// redirect to the view event page // redirect to the view event page
$this->Session->setFlash(__('Event published, but NO mail sent to any participants.', true)); $this->Session->setFlash(__('Event published, but NO mail sent to any participants.', true));
@ -537,16 +537,16 @@ class EventsController extends AppController {
// only allow form submit CSRF protection. // only allow form submit CSRF protection.
if ($this->request->is('post') || $this->request->is('put')) { if ($this->request->is('post') || $this->request->is('put')) {
// send out the email // send out the email
$emailResult = $this->_sendAlertEmail($id); $emailResult = $this->__sendAlertEmail($id);
if (is_bool($emailResult) && $emailResult = true) { if (is_bool($emailResult) && $emailResult = true) {
// Performs all the actions required to publish an event // Performs all the actions required to publish an event
$this->_publish($id); $this->__publish($id);
// redirect to the view event page // redirect to the view event page
$this->Session->setFlash(__('Email sent to all participants.', true)); $this->Session->setFlash(__('Email sent to all participants.', true));
} elseif (!is_bool($emailResult)) { } elseif (!is_bool($emailResult)) {
// Performs all the actions required to publish an event // Performs all the actions required to publish an event
$this->_publish($id); $this->__publish($id);
// redirect to the view event page // redirect to the view event page
$this->Session->setFlash(__('Published but no email sent given GnuPG is not configured.', true)); $this->Session->setFlash(__('Published but no email sent given GnuPG is not configured.', true));
@ -557,7 +557,7 @@ class EventsController extends AppController {
} }
} }
private function _sendAlertEmail($id) { private function __sendAlertEmail($id) {
$this->Event->recursive = 1; $this->Event->recursive = 1;
$event = $this->Event->read(null, $id); $event = $this->Event->read(null, $id);
@ -698,7 +698,7 @@ class EventsController extends AppController {
// User has filled in his contact form, send out the email. // User has filled in his contact form, send out the email.
if ($this->request->is('post') || $this->request->is('put')) { if ($this->request->is('post') || $this->request->is('put')) {
$message = $this->request->data['Event']['message']; $message = $this->request->data['Event']['message'];
if ($this->_sendContactEmail($id, $message)) { if ($this->__sendContactEmail($id, $message)) {
// redirect to the view event page // redirect to the view event page
$this->Session->setFlash(__('Email sent to the reporter.', true)); $this->Session->setFlash(__('Email sent to the reporter.', true));
} else { } else {
@ -716,13 +716,13 @@ class EventsController extends AppController {
* *
* Sends out an email to all people within the same org * Sends out an email to all people within the same org
* with the request to be contacted about a specific event. * with the request to be contacted about a specific event.
* @todo move _sendContactEmail($id, $message) to a better place. (components?) * @todo move __sendContactEmail($id, $message) to a better place. (components?)
* *
* @param unknown_type $id The id of the event for wich you want to contact the org. * @param unknown_type $id The id of the event for wich you want to contact the org.
* @param unknown_type $message The custom message that will be appended to the email. * @param unknown_type $message The custom message that will be appended to the email.
* @return True if success, False if error * @return True if success, False if error
*/ */
private function _sendContactEmail($id, $message) { private function __sendContactEmail($id, $message) {
// fetch the event // fetch the event
$event = $this->Event->read(null, $id); $event = $this->Event->read(null, $id);
$this->loadModel('User'); $this->loadModel('User');

View File

@ -312,7 +312,7 @@ IF (Attribute.category="External analysis", "j", "k"))))))))))'); // TODO hardc
public function afterSave() { public function afterSave() {
if ('db' == Configure::read('CyDefSIG.correlation')) { if ('db' == Configure::read('CyDefSIG.correlation')) {
// update correlation.. // update correlation..
$this->_afterSaveCorrelation($this->data['Attribute']); $this->__afterSaveCorrelation($this->data['Attribute']);
} }
$result = true; $result = true;
@ -340,7 +340,7 @@ IF (Attribute.category="External analysis", "j", "k"))))))))))'); // TODO hardc
if ('db' == Configure::read('CyDefSIG.correlation')) { if ('db' == Configure::read('CyDefSIG.correlation')) {
// update correlation.. // update correlation..
$this->_beforeDeleteCorrelation($this->data['Attribute']['id']); $this->__beforeDeleteCorrelation($this->data['Attribute']['id']);
} }
} }
@ -681,13 +681,13 @@ IF (Attribute.category="External analysis", "j", "k"))))))))))'); // TODO hardc
} }
} }
public function _afterSaveCorrelation($attribute) { private function __afterSaveCorrelation($attribute) {
$this->_beforeDeleteCorrelation($attribute); $this->__beforeDeleteCorrelation($attribute);
// re-add // re-add
$this->setRelatedAttributes($attribute, array('Attribute.id', 'Attribute.event_id', 'Event.date')); $this->setRelatedAttributes($attribute, array('Attribute.id', 'Attribute.event_id', 'Event.date'));
} }
public function _beforeDeleteCorrelation($attribute) { private function __beforeDeleteCorrelation($attribute) {
$this->Correlation = ClassRegistry::init('Correlation'); $this->Correlation = ClassRegistry::init('Correlation');
$dummy = $this->Correlation->deleteAll(array('OR' => array( $dummy = $this->Correlation->deleteAll(array('OR' => array(
'Correlation.1_attribute_id' => $attribute, 'Correlation.1_attribute_id' => $attribute,

View File

@ -31,10 +31,11 @@ App::uses('Helper', 'View');
* @package app.View.Helper * @package app.View.Helper
*/ */
class AppHelper extends Helper { class AppHelper extends Helper {
function url($url = null, $full = false) {
if(is_array($url) && !isset($url['admin'])){ public function url($url = null, $full = false) {
$url['admin'] = false; if (is_array($url) && !isset($url['admin'])) {
} $url['admin'] = false;
return parent::url($url, $full); }
} return parent::url($url, $full);
}
} }