コード例 #1
0
 /**
  * Handle POST requests.
  *
  * @param alpha\Util\Http\Request $request
  *
  * @return alpha\Util\Http\Response
  *
  * @since 1.0
  */
 public function doPOST($request)
 {
     self::$logger->debug('>>doPOST($request=[' . var_export($request, true) . '])');
     $params = $request->getParams();
     $config = ConfigProvider::getInstance();
     $body = View::displayPageHead($this);
     try {
         // check the hidden security fields before accepting the form POST data
         if (!$this->checkSecurityFields()) {
             throw new SecurityException('This page cannot accept post data from remote servers!');
         }
         if (isset($params['createTableBut'])) {
             try {
                 $classname = $params['createTableClass'];
                 $BO = new $classname();
                 $BO->makeTable();
                 self::$logger->action('Created the table for class ' . $classname);
                 $body .= View::displayUpdateMessage('The table for the class ' . $classname . ' has been successfully created.');
             } catch (AlphaException $e) {
                 self::$logger->error($e->getMessage());
                 $body .= View::displayErrorMessage('Error creating the table for the class ' . $classname . ', check the log!');
             }
         }
         if (isset($params['createHistoryTableBut'])) {
             try {
                 $classname = $params['createTableClass'];
                 $BO = new $classname();
                 $BO->makeHistoryTable();
                 self::$logger->action('Created the history table for class ' . $classname);
                 $body .= View::displayUpdateMessage('The history table for the class ' . $classname . ' has been successfully created.');
             } catch (AlphaException $e) {
                 self::$logger->error($e->getMessage());
                 $body .= View::displayErrorMessage('Error creating the history table for the class ' . $classname . ', check the log!');
             }
         }
         if (isset($params['recreateTableClass']) && $params['admin_' . stripslashes($params['recreateTableClass']) . '_button_pressed'] == 'recreateTableBut') {
             try {
                 $classname = $params['recreateTableClass'];
                 $BO = new $classname();
                 $BO->rebuildTable();
                 self::$logger->action('Recreated the table for class ' . $classname);
                 $body .= View::displayUpdateMessage('The table for the class ' . $classname . ' has been successfully recreated.');
             } catch (AlphaException $e) {
                 self::$logger->error($e->getMessage());
                 $body .= View::displayErrorMessage('Error recreating the table for the class ' . $classname . ', check the log!');
             }
         }
         if (isset($params['updateTableClass']) && $params['admin_' . stripslashes($params['updateTableClass']) . '_button_pressed'] == 'updateTableBut') {
             try {
                 $classname = $params['updateTableClass'];
                 $BO = new $classname();
                 $missingFields = $BO->findMissingFields();
                 $count = count($missingFields);
                 for ($i = 0; $i < $count; ++$i) {
                     $BO->addProperty($missingFields[$i]);
                 }
                 self::$logger->action('Updated the table for class ' . $classname);
                 $body .= View::displayUpdateMessage('The table for the class ' . $classname . ' has been successfully updated.');
             } catch (AlphaException $e) {
                 self::$logger->error($e->getMessage());
                 $body .= View::displayErrorMessage('Error updating the table for the class ' . $classname . ', check the log!');
             }
         }
     } catch (SecurityException $e) {
         $body .= View::displayErrorMessage($e->getMessage());
         self::$logger->warn($e->getMessage());
     }
     $body .= $this->displayBodyContent();
     $body .= View::displayPageFoot($this);
     self::$logger->debug('<<doPOST');
     return new Response(200, $body, array('Content-Type' => 'text/html'));
 }
コード例 #2
0
ファイル: LogoutController.php プロジェクト: alphadevx/alpha
 /**
  * Handle GET requests.
  *
  * @param Alpha\Util\Http\Request $request
  *
  * @return Alpha\Util\Http\Response
  *
  * @since 1.0
  */
 public function doGET($request)
 {
     self::$logger->debug('>>doGET($request=[' . var_export($request, true) . '])');
     $params = $request->getParams();
     $config = ConfigProvider::getInstance();
     if ($this->record instanceof Person) {
         self::$logger->debug('Logging out [' . $this->record->get('email') . '] at [' . date('Y-m-d H:i:s') . ']');
         self::$logger->action('Logout');
     }
     $sessionProvider = $config->get('session.provider.name');
     $session = SessionProviderFactory::getInstance($sessionProvider);
     $session->destroy();
     $body = View::displayPageHead($this);
     $body .= View::displayUpdateMessage('You have successfully logged out of the system.');
     $body .= '<div align="center"><a href="' . $config->get('app.url') . '">Home Page</a></div>';
     $body .= View::displayPageFoot($this);
     self::$logger->debug('<<doGET');
     return new Response(200, $body, array('Content-Type' => 'text/html'));
 }
コード例 #3
0
ファイル: CacheController.php プロジェクト: alphadevx/alpha
 /**
  * Handle POST requests.
  *
  * @param Alpha\Util\Http\Response $request
  *
  * @throws Alpha\Exception\SecurityException
  * @throws Alpha\Exception\IllegalArguementException
  *
  * @return Alpha\Util\Http\Response
  *
  * @since 1.0
  */
 public function doPOST($request)
 {
     self::$logger->debug('>>doPOST($request=[' . var_export($request, true) . '])');
     $params = $request->getParams();
     try {
         // check the hidden security fields before accepting the form POST data
         if (!$this->checkSecurityFields()) {
             throw new SecurityException('This page cannot accept post data from remote servers!');
         }
         if (!is_array($params)) {
             throw new IllegalArguementException('Bad $params [' . var_export($params, true) . '] passed to doPOST method!');
         }
         if (isset($params['clearCache']) && $params['clearCache'] == 'true') {
             try {
                 FileUtils::deleteDirectoryContents($this->dataDir, array('.htaccess', 'html', 'images', 'pdf', 'xls'));
                 $this->setStatusMessage(View::displayUpdateMessage('Cache contents deleted successfully.'));
                 $config = ConfigProvider::getInstance();
                 $sessionProvider = $config->get('session.provider.name');
                 $session = SessionProviderFactory::getInstance($sessionProvider);
                 self::$logger->info('Cache contents deleted successfully by user [' . $session->get('currentUser')->get('displayName') . '].');
             } catch (AlphaException $e) {
                 self::$logger->error($e->getMessage());
                 $this->setStatusMessage(View::displayErrorMessage($e->getMessage()));
             }
         }
         return $this->doGET($request);
     } catch (SecurityException $e) {
         $this->setStatusMessage(View::displayErrorMessage($e->getMessage()));
         self::$logger->warn($e->getMessage());
     } catch (IllegalArguementException $e) {
         self::$logger->error($e->getMessage());
         $this->setStatusMessage(View::displayErrorMessage($e->getMessage()));
     }
     $body = View::displayPageHead($this);
     $message = $this->getStatusMessage();
     if (!empty($message)) {
         $body .= $message;
     }
     $body .= View::displayPageFoot($this);
     self::$logger->debug('<<doPOST');
     return new Response(200, $body, array('Content-Type' => 'text/html'));
 }
コード例 #4
0
ファイル: InstallController.php プロジェクト: alphadevx/alpha
 /**
  * Create the directories required by the application.
  *
  * @return string
  *
  * @since 2.0
  */
 public function createApplicationDirs()
 {
     self::$logger->debug('>>createApplicationDirs()');
     $config = ConfigProvider::getInstance();
     $body = '';
     // set the umask first before attempt mkdir
     umask(0);
     /*
      * Create the logs directory, then instantiate a new logger
      */
     $logsDir = $config->get('app.file.store.dir') . 'logs';
     $body .= '<p>Attempting to create the logs directory <em>' . $logsDir . '</em>...';
     if (!file_exists($logsDir)) {
         var_dump(mkdir($logsDir, 0774));
     }
     self::$logger = new Logger('InstallController');
     self::$logger->info('Started installation process!');
     self::$logger->info('Logs directory [' . $logsDir . '] successfully created');
     $body .= View::displayUpdateMessage('Logs directory [' . $logsDir . '] successfully created');
     /*
      * Create the src directory and sub-directories
      */
     $srcDir = $config->get('app.root') . 'src';
     $body .= '<p>Attempting to create the src directory <em>' . $srcDir . '</em>...';
     if (!file_exists($srcDir)) {
         mkdir($srcDir, 0774);
     }
     self::$logger->info('Source directory [' . $srcDir . '] successfully created');
     $body .= View::displayUpdateMessage('Source directory [' . $srcDir . '] successfully created');
     $srcDir = $config->get('app.root') . 'src/Model';
     if (!file_exists($srcDir)) {
         mkdir($srcDir, 0774);
     }
     self::$logger->info('Source directory [' . $srcDir . '] successfully created');
     $body .= View::displayUpdateMessage('Source directory [' . $srcDir . '] successfully created');
     $srcDir = $config->get('app.root') . 'src/View';
     if (!file_exists($srcDir)) {
         mkdir($srcDir, 0774);
     }
     self::$logger->info('Source directory [' . $srcDir . '] successfully created');
     $body .= View::displayUpdateMessage('Source directory [' . $srcDir . '] successfully created');
     /*
      * Create the attachments directory
      */
     $attachmentsDir = $config->get('app.file.store.dir') . 'attachments';
     $body .= '<p>Attempting to create the attachments directory <em>' . $attachmentsDir . '</em>...';
     if (!file_exists($attachmentsDir)) {
         mkdir($attachmentsDir, 0774);
     }
     self::$logger->info('Attachments directory [' . $attachmentsDir . '] successfully created');
     $body .= View::displayUpdateMessage('Attachments directory [' . $attachmentsDir . '] successfully created');
     /*
      * Create the cache directory and sub-directories
      */
     $cacheDir = $config->get('app.file.store.dir') . 'cache';
     $htmlDir = $config->get('app.file.store.dir') . 'cache/html';
     $imagesDir = $config->get('app.file.store.dir') . 'cache/images';
     $pdfDir = $config->get('app.file.store.dir') . 'cache/pdf';
     $xlsDir = $config->get('app.file.store.dir') . 'cache/xls';
     // cache
     $body .= '<p>Attempting to create the cache directory <em>' . $cacheDir . '</em>...';
     if (!file_exists($cacheDir)) {
         mkdir($cacheDir, 0774);
     }
     self::$logger->info('Cache directory [' . $cacheDir . '] successfully created');
     $body .= View::displayUpdateMessage('Cache directory [' . $cacheDir . '] successfully created');
     // cache/html
     $body .= '<p>Attempting to create the HTML cache directory <em>' . $htmlDir . '</em>...';
     if (!file_exists($htmlDir)) {
         mkdir($htmlDir, 0774);
     }
     self::$logger->info('Cache directory [' . $htmlDir . '] successfully created');
     $body .= View::displayUpdateMessage('Cache directory [' . $htmlDir . '] successfully created');
     // cache/images
     $body .= '<p>Attempting to create the cache directory <em>' . $imagesDir . '</em>...';
     if (!file_exists($imagesDir)) {
         mkdir($imagesDir, 0774);
     }
     self::$logger->info('Cache directory [' . $imagesDir . '] successfully created');
     $body .= View::displayUpdateMessage('Cache directory [' . $imagesDir . '] successfully created');
     // cache/pdf
     $body .= '<p>Attempting to create the cache directory <em>' . $pdfDir . '</em>...';
     if (!file_exists($pdfDir)) {
         mkdir($pdfDir, 0774);
     }
     self::$logger->info('Cache directory [' . $pdfDir . '] successfully created');
     $body .= View::displayUpdateMessage('Cache directory [' . $pdfDir . '] successfully created');
     // cache/xls
     $body .= '<p>Attempting to create the cache directory <em>' . $xlsDir . '</em>...';
     if (!file_exists($xlsDir)) {
         mkdir($xlsDir, 0774);
     }
     self::$logger->info('Cache directory [' . $xlsDir . '] successfully created');
     $body .= View::displayUpdateMessage('Cache directory [' . $xlsDir . '] successfully created');
     self::$logger->debug('<<createApplicationDirs');
     return $body;
 }
コード例 #5
0
ファイル: SearchController.php プロジェクト: alphadevx/alpha
 /**
  * Method for rendering the pagination links.
  *
  * @return string
  *
  * @since 1.0
  */
 protected function renderPageLinks()
 {
     $config = ConfigProvider::getInstance();
     $params = $this->request->getParams();
     $body = '';
     $end = $this->startPoint + $config->get('app.list.page.amount');
     if ($end > $this->resultCount) {
         $end = $this->resultCount;
     }
     if ($this->resultCount > 0) {
         $body .= '<p align="center">Displaying ' . ($this->startPoint + 1) . ' to ' . $end . ' of <strong>' . $this->resultCount . '</strong>.&nbsp;&nbsp;';
     } else {
         if (!empty($this->query)) {
             $body .= View::displayUpdateMessage('There were no search results for your query.');
         }
     }
     $body .= '<ul class="pagination">';
     if ($this->startPoint > 0) {
         // handle secure URLs
         if (isset($params['tk'])) {
             $body .= '<li><a href="' . FrontController::generateSecureURL('act=Search&q=' . $this->query . '&start=' . ($this->startPoint - $config->get('app.list.page.amount'))) . '">&laquo;</a></li>';
         } else {
             $body .= '<li><a href="' . $config->get('app.url') . '/search/' . $this->query . '/' . ($this->startPoint - $config->get('app.list.page.amount')) . '">&laquo;</a></li>';
         }
     } elseif ($this->resultCount > $config->get('app.list.page.amount')) {
         $body .= '<li class="disabled"><a href="#">&laquo;</a></li>';
     }
     $page = 1;
     for ($i = 0; $i < $this->resultCount; $i += $config->get('app.list.page.amount')) {
         if ($i != $this->startPoint) {
             // handle secure URLs
             if (isset($params['tk'])) {
                 $body .= '<li><a href="' . FrontController::generateSecureURL('act=Search&q=' . $this->query . '&start=' . $i) . '">' . $page . '</a></li>';
             } else {
                 $body .= '<li><a href="' . $config->get('app.url') . '/search/' . $this->query . '/' . $i . '">' . $page . '</a></li>';
             }
         } elseif ($this->resultCount > $config->get('app.list.page.amount')) {
             $body .= '<li class="active"><a href="#">' . $page . '</a></li>';
         }
         ++$page;
     }
     if ($this->resultCount > $end) {
         // handle secure URLs
         if (isset($params['tk'])) {
             $body .= '<li><a href="' . FrontController::generateSecureURL('act=Search&q=' . $this->query . '&start=' . ($this->startPoint + $config->get('app.list.page.amount'))) . '">Next-&gt;&gt;</a></li>';
         } else {
             $body .= '<li><a href="' . $config->get('app.url') . '/search/' . $this->query . '/' . ($this->startPoint + $config->get('app.list.page.amount')) . '">&raquo;</a></li>';
         }
     } elseif ($this->resultCount > $config->get('app.list.page.amount')) {
         $body .= '<li class="disabled"><a href="#">&raquo;</a></li>';
     }
     $body .= '</ul>';
     $body .= '</p>';
     return $body;
 }
コード例 #6
0
 /**
  * Method to handle DELETE requests.
  *
  * @param Alpha\Util\Http\Request $request
  *
  * @throws Alpha\Exception\IllegalArguementException
  * @throws Alpha\Exception\SecurityException
  *
  * @return Alpha\Util\Http\Response
  *
  * @since 2.0
  */
 public function doDELETE($request)
 {
     self::$logger->debug('>>doDELETE(request=[' . var_export($request, true) . '])');
     $config = ConfigProvider::getInstance();
     $params = $request->getParams();
     $accept = $request->getAccept();
     try {
         // check the hidden security fields before accepting the form data
         if (!$this->checkSecurityFields()) {
             throw new SecurityException('This page cannot accept data from remote servers!');
         }
         if (isset($params['ActiveRecordType'])) {
             $ActiveRecordType = urldecode($params['ActiveRecordType']);
         } else {
             throw new IllegalArguementException('No ActiveRecord available to edit!');
         }
         if (class_exists($ActiveRecordType)) {
             $record = new $ActiveRecordType();
         } else {
             throw new IllegalArguementException('No ActiveRecord [' . $ActiveRecordType . '] available to edit!');
         }
         // check the hidden security fields before accepting the form POST data
         if (!$this->checkSecurityFields()) {
             throw new SecurityException('This page cannot accept post data from remote servers!');
         }
         $record->load($params['ActiveRecordOID']);
         ActiveRecord::begin();
         $record->delete();
         ActiveRecord::commit();
         ActiveRecord::disconnect();
         self::$logger->action('Deleted ' . $ActiveRecordType . ' instance with OID ' . $params['ActiveRecordOID']);
         if ($accept == 'application/json') {
             $response = new Response(200);
             $response->setHeader('Content-Type', 'application/json');
             $response->setBody(json_encode(array('message' => 'deleted')));
         } else {
             $response = new Response(301);
             if (isset($params['statusMessage'])) {
                 $this->setStatusMessage(View::displayUpdateMessage($params['statusMessage']));
             } else {
                 $this->setStatusMessage(View::displayUpdateMessage('Deleted'));
             }
             if ($this->getNextJob() != '') {
                 $response->redirect($this->getNextJob());
             } else {
                 if ($this->request->isSecureURI()) {
                     $response->redirect(FrontController::generateSecureURL('act=Alpha\\Controller\\ActiveRecordController&ActiveRecordType=' . $ActiveRecordType . '&start=0&limit=' . $config->get('app.list.page.amount')));
                 } else {
                     $response->redirect($config->get('app.url') . '/records/' . $params['ActiveRecordType']);
                 }
             }
         }
     } catch (SecurityException $e) {
         self::$logger->warn($e->getMessage());
         throw new ResourceNotAllowedException($e->getMessage());
     } catch (RecordNotFoundException $e) {
         self::$logger->warn($e->getMessage());
         throw new ResourceNotFoundException('The item that you have requested cannot be found!');
     } catch (AlphaException $e) {
         self::$logger->error($e->getMessage());
         ActiveRecord::rollback();
     }
     self::$logger->debug('<<doDELETE');
     return $response;
 }
コード例 #7
0
ファイル: DEnumController.php プロジェクト: alphadevx/alpha
 /**
  * Method to create the DEnum tables if they don't exist.
  *
  * @since 1.0
  *
  * @return string
  */
 private function createDEnumTables()
 {
     $tmpDEnum = new DEnum();
     $body = '<p>Attempting to build table ' . DEnum::TABLE_NAME . ' for class DEnum : </p>';
     try {
         $tmpDEnum->makeTable();
         $body .= View::displayUpdateMessage('Successfully re-created the database table ' . DEnum::TABLE_NAME);
         self::$logger->action('Re-created the table ' . DEnum::TABLE_NAME);
     } catch (AlphaException $e) {
         $body .= View::displayErrorMessage('Failed re-created the database table ' . DEnum::TABLE_NAME . ', check the log');
         self::$logger->error($e->getMessage());
     }
     $tmpDEnumItem = new DEnumItem();
     $body .= '<p>Attempting to build table ' . DEnumItem::TABLE_NAME . ' for class DEnumItem : </p>';
     try {
         $tmpDEnumItem->makeTable();
         $body .= View::displayUpdateMessage('Successfully re-created the database table ' . DEnumItem::TABLE_NAME);
         self::$logger->action('Re-created the table ' . DEnumItem::TABLE_NAME);
     } catch (AlphaException $e) {
         $body .= View::displayErrorMessage('Failed re-created the database table ' . DEnumItem::TABLE_NAME . ', check the log');
         self::$logger->error($e->getMessage());
     }
     return $body;
 }
コード例 #8
0
ファイル: LoginController.php プロジェクト: alphadevx/alpha
 /**
  * Handle POST requests (adds $currentUser Person to the session).
  *
  * @param Alpha\Util\Http\Request $request
  *
  * @return Alpha\Util\Http\Response
  *
  * @throws Alpha\Exception\IllegalArguementException
  *
  * @since 1.0
  */
 public function doPOST($request)
 {
     self::$logger->debug('>>doPOST($request=[' . var_export($request, true) . '])');
     $params = $request->getParams();
     if (!is_array($params)) {
         throw new IllegalArguementException('Bad $params [' . var_export($params, true) . '] passed to doPOST method!');
     }
     $config = ConfigProvider::getInstance();
     $body = '';
     try {
         // check the hidden security fields before accepting the form POST data
         if (!$this->checkSecurityFields()) {
             throw new SecurityException('This page cannot accept post data from remote servers!');
         }
         if (isset($params['loginBut'])) {
             // if the database has not been set up yet, accept a login from the config admin username/password
             if (!ActiveRecord::isInstalled()) {
                 if ($params['email'] == $config->get('app.install.username') && password_verify($params['password'], password_hash($config->get('app.install.password'), PASSWORD_DEFAULT, ['cost' => 12]))) {
                     self::$logger->info('Logging in [' . $params['email'] . '] at [' . date('Y-m-d H:i:s') . ']');
                     $admin = new Person();
                     $admin->set('displayName', 'Admin');
                     $admin->set('email', $params['email']);
                     $admin->set('password', password_hash($params['password'], PASSWORD_DEFAULT, ['cost' => 12]));
                     $admin->set('OID', '00000000001');
                     $sessionProvider = $config->get('session.provider.name');
                     $session = SessionProviderFactory::getInstance($sessionProvider);
                     $session->set('currentUser', $admin);
                     $response = new Response(301);
                     if ($this->getNextJob() != '') {
                         $response->redirect(FrontController::generateSecureURL('act=' . $this->getNextJob()));
                         $this->clearUnitOfWorkAttributes();
                     } else {
                         $response->redirect(FrontController::generateSecureURL('act=InstallController'));
                     }
                     return $response;
                 } else {
                     throw new ValidationException('Failed to login user ' . $params['email'] . ', the password is incorrect!');
                 }
             } else {
                 // here we are attempting to load the person from the email address
                 $this->personObject->loadByAttribute('email', $params['email'], true);
                 ActiveRecord::disconnect();
                 // checking to see if the account has been disabled
                 if (!$this->personObject->isTransient() && $this->personObject->get('state') == 'Disabled') {
                     throw new SecurityException('Failed to login user ' . $params['email'] . ', that account has been disabled!');
                 }
                 // check the password
                 return $this->doLoginAndRedirect($params['password']);
             }
             $body .= View::displayPageHead($this);
             $body .= $this->personView->displayLoginForm();
         }
         if (isset($params['resetBut'])) {
             // here we are attempting to load the person from the email address
             $this->personObject->loadByAttribute('email', $params['email']);
             ActiveRecord::disconnect();
             // generate a new random password
             $newPassword = $this->personObject->generatePassword();
             // now encrypt and save the new password, then e-mail the user
             $this->personObject->set('password', password_hash($newPassword, PASSWORD_DEFAULT, ['cost' => 12]));
             $this->personObject->save();
             $message = 'The password for your account has been reset to ' . $newPassword . ' as you requested.  You can now login to the site using your ' . 'e-mail address and this new password as before.';
             $subject = 'Password change request';
             $this->personObject->sendMail($message, $subject);
             $body .= View::displayUpdateMessage('The password for the user <strong>' . $params['email'] . '</strong> has been reset, and the new password ' . 'has been sent to that e-mail address.');
             $body .= '<a href="' . $config->get('app.url') . '">Home Page</a>';
         }
     } catch (ValidationException $e) {
         $body .= View::displayPageHead($this);
         $body .= View::displayErrorMessage($e->getMessage());
         if (isset($params['reset'])) {
             $body .= $this->personView->displayResetForm();
         } else {
             $body .= $this->personView->displayLoginForm();
         }
         self::$logger->warn($e->getMessage());
     } catch (SecurityException $e) {
         $body .= View::displayPageHead($this);
         $body .= View::displayErrorMessage($e->getMessage());
         self::$logger->warn($e->getMessage());
     } catch (RecordNotFoundException $e) {
         $body .= View::displayPageHead($this);
         $body .= View::displayErrorMessage('Failed to find the user \'' . $params['email'] . '\'');
         if (isset($params['reset'])) {
             $body .= $this->personView->displayResetForm();
         } else {
             $body .= $this->personView->displayLoginForm();
         }
         self::$logger->warn($e->getMessage());
     }
     $body .= View::displayPageFoot($this);
     self::$logger->debug('<<doPOST');
     return new Response(200, $body, array('Content-Type' => 'text/html'));
 }
コード例 #9
0
ファイル: TagController.php プロジェクト: alphadevx/alpha
 /**
  * Handle POST requests.
  *
  * @param Alpha\Util\Http\Request $request
  *
  * @return Alpha\Util\Http\Response
  *
  * @throws Alpha\Exception\SecurityException
  * @throws Alpha\Exception\IllegalArguementException
  *
  * @since 1.0
  */
 public function doPOST($request)
 {
     self::$logger->debug('>>doPOST($request=[' . var_export($request, true) . '])');
     $params = $request->getParams();
     try {
         // check the hidden security fields before accepting the form POST data
         if (!$this->checkSecurityFields()) {
             throw new SecurityException('This page cannot accept post data from remote servers!');
         }
         if (isset($params['clearTaggedClass']) && $params['clearTaggedClass'] != '') {
             try {
                 self::$logger->info('About to start rebuilding the tags for the class [' . $params['clearTaggedClass'] . ']');
                 $startTime = microtime(true);
                 $record = new $params['clearTaggedClass']();
                 $records = $record->loadAll();
                 self::$logger->info('Loaded all of the active records (elapsed time [' . round(microtime(true) - $startTime, 5) . '] seconds)');
                 ActiveRecord::begin();
                 $tag = new Tag();
                 $tag->deleteAllByAttribute('taggedClass', $params['clearTaggedClass']);
                 self::$logger->info('Deleted all of the old tags (elapsed time [' . round(microtime(true) - $startTime, 5) . '] seconds)');
                 $this->regenerateTagsOnRecords($records);
                 self::$logger->info('Saved all of the new tags (elapsed time [' . round(microtime(true) - $startTime, 5) . '] seconds)');
                 self::$logger->action('Tags recreated on the [' . $params['clearTaggedClass'] . '] class');
                 ActiveRecord::commit();
                 $this->setStatusMessage(View::displayUpdateMessage('Tags recreated on the ' . $record->getFriendlyClassName() . ' class.'));
                 self::$logger->info('Tags recreated on the [' . $params['clearTaggedClass'] . '] class (time taken [' . round(microtime(true) - $startTime, 5) . '] seconds).');
             } catch (AlphaException $e) {
                 self::$logger->error($e->getMessage());
                 ActiveRecord::rollback();
             }
             ActiveRecord::disconnect();
             return $this->doGET($request);
         } elseif (isset($params['ActiveRecordType']) && isset($params['ActiveRecordOID'])) {
             $ActiveRecordType = urldecode($params['ActiveRecordType']);
             $ActiveRecordOID = $params['ActiveRecordOID'];
             if (class_exists($ActiveRecordType)) {
                 $record = new $ActiveRecordType();
             } else {
                 throw new IllegalArguementException('No ActiveRecord available to display tags for!');
             }
             if (isset($params['saveBut'])) {
                 try {
                     $record->load($ActiveRecordOID);
                     $tags = $record->getPropObject('tags')->getRelatedObjects();
                     ActiveRecord::begin();
                     foreach ($tags as $tag) {
                         $tag->set('content', Tag::cleanTagContent($params['content_' . $tag->getID()]));
                         $tag->save();
                         self::$logger->action('Saved tag ' . $tag->get('content') . ' on ' . $ActiveRecordType . ' instance with OID ' . $ActiveRecordOID);
                     }
                     // handle new tag if posted
                     if (isset($params['NewTagValue']) && trim($params['NewTagValue']) != '') {
                         $newTag = new Tag();
                         $newTag->set('content', Tag::cleanTagContent($params['NewTagValue']));
                         $newTag->set('taggedOID', $ActiveRecordOID);
                         $newTag->set('taggedClass', $ActiveRecordType);
                         $newTag->save();
                         self::$logger->action('Created a new tag ' . $newTag->get('content') . ' on ' . $ActiveRecordType . ' instance with OID ' . $ActiveRecordOID);
                     }
                     ActiveRecord::commit();
                     $this->setStatusMessage(View::displayUpdateMessage('Tags on ' . get_class($record) . ' ' . $record->getID() . ' saved successfully.'));
                     return $this->doGET($request);
                 } catch (ValidationException $e) {
                     /*
                      * The unique key has most-likely been violated because this BO is already tagged with this
                      * value.
                      */
                     ActiveRecord::rollback();
                     $this->setStatusMessage(View::displayErrorMessage('Tags on ' . get_class($record) . ' ' . $record->getID() . ' not saved due to duplicate tag values, please try again.'));
                     return $this->doGET($request);
                 } catch (FailedSaveException $e) {
                     self::$logger->error('Unable to save the tags of id [' . $params['ActiveRecordOID'] . '], error was [' . $e->getMessage() . ']');
                     ActiveRecord::rollback();
                     $this->setStatusMessage(View::displayErrorMessage('Tags on ' . get_class($record) . ' ' . $record->getID() . ' not saved, please check the application logs.'));
                     return $this->doGET($request);
                 }
                 ActiveRecord::disconnect();
             }
         } else {
             return parent::doPOST($request);
         }
     } catch (SecurityException $e) {
         $this->setStatusMessage(View::displayErrorMessage($e->getMessage()));
         self::$logger->warn($e->getMessage());
     } catch (IllegalArguementException $e) {
         self::$logger->error($e->getMessage());
     } catch (RecordNotFoundException $e) {
         self::$logger->warn($e->getMessage());
         $this->setStatusMessage(View::displayErrorMessage('Failed to load the requested item from the database!'));
     }
     self::$logger->debug('<<doPOST');
 }
コード例 #10
0
ファイル: ArticleController.php プロジェクト: alphadevx/alpha
 /**
  * Method to handle PUT requests.
  *
  * @param Alpha\Util\Http\Request
  *
  * @return Alpha\Util\Http\Response
  *
  * @since 1.0
  */
 public function doPUT($request)
 {
     self::$logger->debug('>>doPUT($request=[' . var_export($request, true) . '])');
     $config = ConfigProvider::getInstance();
     $params = $request->getParams();
     try {
         // check the hidden security fields before accepting the form POST data
         if (!$this->checkSecurityFields()) {
             throw new SecurityException('This page cannot accept post data from remote servers!');
             self::$logger->debug('<<doPUT');
         }
         if (isset($params['markdownTextBoxRows']) && $params['markdownTextBoxRows'] != '') {
             $viewState = ViewState::getInstance();
             $viewState->set('markdownTextBoxRows', $params['markdownTextBoxRows']);
         }
         if (isset($params['title']) || isset($params['ActiveRecordOID'])) {
             if (isset($params['ActiveRecordType']) && class_exists($params['ActiveRecordType'])) {
                 $record = new $params['ActiveRecordType']();
             } else {
                 $record = new Article();
             }
             if (isset($params['title'])) {
                 $title = str_replace($config->get('cms.url.title.separator'), ' ', $params['title']);
                 $record->loadByAttribute('title', $title, false, array('OID', 'version_num', 'created_ts', 'updated_ts', 'title', 'author', 'published', 'content', 'headerContent'));
             } else {
                 $record->load($params['ActiveRecordOID']);
             }
             // uploading an article attachment
             if (isset($params['uploadBut'])) {
                 $source = $request->getFile('userfile')['tmp_name'];
                 $dest = $record->getAttachmentsLocation() . '/' . $request->getFile('userfile')['name'];
                 // upload the file to the attachments directory
                 FileUtils::copy($source, $dest);
                 if (!file_exists($dest)) {
                     throw new AlphaException('Could not move the uploaded file [' . $request->getFile('userfile')['name'] . ']');
                 }
                 // set read/write permissions on the file
                 $success = chmod($dest, 0666);
                 if (!$success) {
                     throw new AlphaException('Unable to set read/write permissions on the uploaded file [' . $dest . '].');
                 }
                 if ($success) {
                     self::$logger->action('File ' . $source . ' uploaded to ' . $dest);
                     $this->setStatusMessage(View::displayUpdateMessage('File ' . $source . ' uploaded to ' . $dest));
                 }
             } elseif (isset($params['deletefile']) && $params['deletefile'] != '') {
                 $success = unlink($record->getAttachmentsLocation() . '/' . $params['deletefile']);
                 if (!$success) {
                     throw new AlphaException('Could not delete the file [' . $params['deletefile'] . ']');
                 }
                 if ($success) {
                     self::$logger->action('File ' . $record->getAttachmentsLocation() . '/' . $params['deletefile'] . ' deleted');
                     $this->setStatusMessage(View::displayUpdateMessage('File ' . $record->getAttachmentsLocation() . '/' . $params['deletefile'] . ' deleted'));
                 }
             } else {
                 self::$logger->debug('<<doPUT');
                 return parent::doPUT($request);
             }
         } else {
             throw new IllegalArguementException('No valid article ID provided!');
         }
     } catch (SecurityException $e) {
         $this->setStatusMessage(View::displayErrorMessage($e->getMessage()));
         self::$logger->warn($e->getMessage());
     } catch (IllegalArguementException $e) {
         $this->setStatusMessage(View::displayErrorMessage($e->getMessage()));
         self::$logger->error($e->getMessage());
     } catch (RecordNotFoundException $e) {
         self::$logger->warn($e->getMessage());
         $this->setStatusMessage(View::displayErrorMessage('Failed to load the requested article from the database!'));
     } catch (AlphaException $e) {
         $this->setStatusMessage(View::displayErrorMessage($e->getMessage()));
         self::$logger->error($e->getMessage());
     }
     $response = new Response(301);
     if ($this->getNextJob() != '') {
         $response->redirect($this->getNextJob());
     } else {
         if ($this->request->isSecureURI()) {
             $response->redirect(FrontController::generateSecureURL('act=Alpha\\Controller\\ActiveRecordController&ActiveRecordType=Alpha\\Model\\Article&ActiveRecordOID=' . $record->getOID() . '&view=edit'));
         } else {
             $title = str_replace(' ', $config->get('cms.url.title.separator'), $record->get('title'));
             $response->redirect($config->get('app.url') . '/a/' . $title . '/edit');
         }
     }
     self::$logger->debug('<<doPUT');
     return $response;
 }