예제 #1
0
 /**
  * PING
  *
  * @param string|null $url pingのURL(テストで使用する)
  * @return mixed fsockopenの結果
  */
 public function ping($url = null)
 {
     //サイトの生死確認
     $errno = 0;
     $errstr = null;
     if (!$url) {
         $url = self::NOTIFICATION_PING_URL;
     }
     CakeLog::info('Execute ping ' . $url);
     try {
         $resource = fsockopen($url, 80, $errno, $errstr, 3);
     } catch (Exception $ex) {
         $resource = false;
         CakeLog::error($ex);
     }
     if (!$resource) {
         CakeLog::info('Failure ping ' . $url);
         $result = false;
     } else {
         fclose($resource);
         $result = true;
         CakeLog::info('Success ping ' . $url);
     }
     return $result;
 }
예제 #2
0
 /**
  * Bower update
  *
  * @param Model $model Model using this behavior
  * @param string $plugin Plugin namespace
  * @param string $option It is '' or '--save'. '--save' is used install.
  * @return bool True on success
  */
 public function updateBower(Model $model, $plugin, $option = '')
 {
     if (!$plugin) {
         return false;
     }
     $pluginPath = ROOT . DS . 'app' . DS . 'Plugin' . DS . Inflector::camelize($plugin) . DS;
     if (!file_exists($pluginPath . 'bower.json')) {
         return true;
     }
     $file = new File($pluginPath . 'bower.json');
     $bower = json_decode($file->read(), true);
     $file->close();
     foreach ($bower['dependencies'] as $package => $version) {
         CakeLog::info(sprintf('[bower] Start bower install %s#%s for %s', $package, $version, $plugin));
         $messages = array();
         $ret = null;
         exec(sprintf('cd %s && `which bower` --allow-root install %s#%s %s', ROOT, $package, $version, $option), $messages, $ret);
         // Write logs
         if (Configure::read('debug')) {
             foreach ($messages as $message) {
                 CakeLog::info(sprintf('[bower]   %s', $message));
             }
         }
         CakeLog::info(sprintf('[bower] Successfully bower install %s#%s for %s', $package, $version, $plugin));
     }
     return true;
 }
예제 #3
0
 /**
  * onActivate will be called if this returns true
  *
  * @param  object $controller Controller
  * @return boolean
  */
 public function beforeActivation(&$controller)
 {
     if (!CakePlugin::loaded('Imagine')) {
         $plugins = App::objects('plugins');
         if (in_array('Imagine', $plugins)) {
             $plugin = new CroogoPlugin();
             $plugin->addBootstrap('Imagine');
             CakePlugin::load('Imagine');
             CakeLog::info('Imagine plugin added to bootstrap');
         }
     }
     return true;
 }
예제 #4
0
 /**
  * Plugin migration
  *
  * @param Model $model Model using this behavior
  * @param string $plugin Plugin key
  * @return bool True on success
  */
 public function runMigration(Model $model, $plugin = null)
 {
     if (!$plugin) {
         return false;
     }
     $connections = array('master');
     $plugin = Inflector::camelize($plugin);
     foreach ($connections as $connection) {
         CakeLog::info(sprintf('[migration] Start migrating %s for %s connection', $plugin, $connection));
         $messages = array();
         $ret = null;
         exec(sprintf('cd %s && app/Console/cake Migrations.migration run all -p %s -c %s -i %s', ROOT, $plugin, $connection, $connection), $messages, $ret);
         // Write logs
         if (Configure::read('debug')) {
             foreach ($messages as $message) {
                 CakeLog::info(sprintf('[migration]   %s', $message));
             }
         }
         CakeLog::info(sprintf('[migration] Successfully migrated %s for %s connection', $plugin, $connection));
     }
     return true;
 }
예제 #5
0
 public function handleBookState($bookState)
 {
     $ret = false;
     switch ($bookState) {
         case BookData::FILES_STATE_NONE:
             CakeLog::info('[BookFilesManager::handleBookState] Book File Add State None: ' . $this->bookId);
             $this->completedState = BookData::FILES_STATE_INIT;
             $ret = true;
             break;
         case BookData::FILES_STATE_INIT:
             CakeLog::info('[BookFilesManager::handleBookState] Copying Files to Book Directory: ' . $this->bookId);
             $this->completedState = BookData::FILES_STATE_COPIED;
             $objProcessor = new BookFilesProcessor($this->bookId);
             $objProcessor->importFiles = $this->options['files'];
             if (count($objProcessor->importFiles) > 0) {
                 $ret = $objProcessor->process();
             } else {
                 $ret = true;
             }
             break;
         case BookData::FILES_STATE_COPIED:
             CakeLog::info('[BookFilesManager::handleBookState] Files Copied: ' . $this->bookId);
             $this->completedState = BookData::FILES_STATE_COMPLETE;
             $ret = true;
             break;
         case BookData::FILES_STATE_COMPLETE:
             CakeLog::info('[BookFilesManager::handleBookState] File add Complete: ' . $this->bookId);
             $bookItem = $this->bookData->getBookItem(true);
             $bookItem['ChChaucerBookVersion']['processing_progress'] = 1.0;
             $this->bookData->saveBookVersion($bookItem);
             $this->setComplete();
             $ret = true;
             break;
     }
     return $ret;
 }
예제 #6
0
 private function logMe($msg)
 {
     CakeLog::info($msg, 'sensors');
 }
예제 #7
0
 public function delete($id = null)
 {
     if (AuthComponent::user('role') != 'admin') {
         throw new ForbiddenException("Você não tem permissão para executar esta ação.");
     }
     $this->User->id = $id;
     if (!$this->User->exists()) {
         throw new NotFoundException(__('Invalid user'));
     }
     if ($this->User->delete()) {
         # Store log
         CakeLog::info('The user ' . AuthComponent::user('username') . ' (ID: ' . AuthComponent::user('id') . ') deleted user (ID: ' . $this->User->id . ')', 'users');
         $this->Session->setFlash(__('User deleted'), 'flash_success');
         $this->redirect('/home');
     }
     $this->Session->setFlash(__('User was not deleted'), 'flash_fail');
     $this->redirect('/home');
 }
예제 #8
0
 public function info($message)
 {
     CakeLog::info($message, $this->scope);
 }
 /**
  * The customerCreate method prepares data for Stripe_Customer::create and attempts to
  * create a customer.
  *
  * @param array	$data The data passed directly to Stripe's API.
  * @return array $customer if success, string $error if failure.
  */
 public function customerCreate($data)
 {
     // for API compatibility with version 1.x of this component
     if (isset($data['stripeToken'])) {
         $data['card'] = $data['stripeToken'];
         unset($data['stripeToken']);
     }
     Stripe::setApiKey($this->key);
     $error = null;
     try {
         $customer = Stripe_Customer::create($data);
     } catch (Stripe_CardError $e) {
         $body = $e->getJsonBody();
         $err = $body['error'];
         CakeLog::error('Customer::Stripe_CardError: ' . $err['type'] . ': ' . $err['code'] . ': ' . $err['message'], 'stripe');
         $error = $err['message'];
     } catch (Stripe_InvalidRequestError $e) {
         $body = $e->getJsonBody();
         $err = $body['error'];
         CakeLog::error('Customer::Stripe_InvalidRequestError: ' . $err['type'] . ': ' . $err['message'], 'stripe');
         $error = $err['message'];
     } catch (Stripe_AuthenticationError $e) {
         CakeLog::error('Customer::Stripe_AuthenticationError: API key rejected!', 'stripe');
         $error = 'Payment processor API key error.';
     } catch (Stripe_ApiConnectionError $e) {
         CakeLog::error('Customer::Stripe_ApiConnectionError: Stripe could not be reached.', 'stripe');
         $error = 'Network communication with payment processor failed, try again later';
     } catch (Stripe_Error $e) {
         CakeLog::error('Customer::Stripe_Error: Stripe could be down.', 'stripe');
         $error = 'Payment processor error, try again later.';
     } catch (Exception $e) {
         CakeLog::error('Customer::Exception: Unknown error.', 'stripe');
         $error = 'There was an error, try again later.';
     }
     if ($error !== null) {
         // an error is always a string
         return (string) $error;
     }
     CakeLog::info('Customer: customer id ' . $customer->id, 'stripe');
     return $this->_formatResult($customer);
 }
예제 #10
0
 /**
  * ステップ 3
  * データベース設定
  *
  * @return void
  */
 public function init_db()
 {
     $this->set('pageTitle', __d('install', 'Database Settings'));
     // Destroy session in order to handle ping request
     $this->Session->destroy();
     $this->set('masterDB', $this->InstallUtil->chooseDBByEnvironment());
     $this->set('errors', array());
     $this->set('validationErrors', array());
     if ($this->request->is('post')) {
         set_time_limit(1800);
         if ($this->request->data['prefix'] && substr($this->request->data['prefix'], -1, 1) !== '_') {
             $this->request->data['prefix'] .= '_';
         }
         if ($this->InstallUtil->validatesDBConf($this->request->data)) {
             $this->InstallUtil->saveDBConf($this->request->data);
         } else {
             $this->set('validationErrors', $this->InstallUtil->validationErrors);
             $this->response->statusCode(400);
             $this->set('errors', [__d('net_commons', 'Failed on validation errors. Please check the input data.')]);
             CakeLog::info('[ValidationErrors] ' . $this->request->here());
             if (Configure::read('debug')) {
                 CakeLog::info(var_export($this->InstallUtil->validationErrors, true));
             }
             return;
         }
         if (!$this->InstallUtil->createDB($this->request->data)) {
             $this->response->statusCode(400);
             CakeLog::info('Failed to create database.');
             $this->set('errors', [__d('install', 'Failed to create database.')]);
             return;
         }
         // Install migrations
         $plugins = array_unique(array_merge(App::objects('plugins'), array_map('basename', glob(ROOT . DS . 'app' . DS . 'Plugin' . DS . '*', GLOB_ONLYDIR))));
         if (!$this->InstallUtil->installMigrations('master', $plugins)) {
             $this->response->statusCode(400);
             CakeLog::error('Failed to install migrations');
             $this->set('errors', [__d('install', 'Failed to install migrations.')]);
             return;
         }
         $this->redirect(array('action' => 'init_admin_user', '?' => ['language' => Configure::read('Config.language')]));
     }
 }
예제 #11
0
 /**
  * Composer update
  *
  * @param Model $model Model using this behavior
  * @param string $package Plugin namespace
  * @param string $option It is 'update' or 'require --dev'. 'require --dev' is used install.
  * @return bool True on success
  */
 public function updateComposer(Model $model, $package, $option = 'update')
 {
     static $hhvm = null;
     if (!$package) {
         return false;
     }
     if (!isset($hhvm)) {
         // Use hhvm only if php version greater than 5.5.0 and hhvm installed
         // @see https://github.com/facebook/hhvm/wiki/OSS-PHP-Frameworks-Unit-Testing
         $gt55 = version_compare(phpversion(), '5.5.0', '>=');
         exec('which hhvm', $messages, $ret);
         $hhvm = $gt55 && $ret === 0 ? 'hhvm -vRepo.Central.Path=/var/run/hhvm/hhvm.hhbc' : '';
     }
     CakeLog::info(sprintf('[composer] Start composer %s %s', $option, $package));
     $messages = array();
     $ret = null;
     $cmd = sprintf('export COMPOSER_HOME=%s && cd %s && %s `which composer` %s %s 2>&1', ROOT, ROOT, $hhvm, $option, $package);
     exec($cmd, $messages, $ret);
     // Write logs
     if (Configure::read('debug') || $ret !== 0) {
         foreach ($messages as $message) {
             CakeLog::info(sprintf('[composer]   %s', $message));
         }
     }
     if ($ret !== 0) {
         return false;
     }
     CakeLog::info(sprintf('[composer] Successfully composer %s %s', $option, $package));
     return true;
 }
예제 #12
0
 /**
  * Copy font files used by admin ui
  *
  * @throws Exception
  */
 protected function _copyFonts()
 {
     $fontAwesomePath = WWW_ROOT . 'fontAwesome';
     if (!file_exists($fontAwesomePath)) {
         if (!$this->_clone) {
             throw new Exception('You don\'t have "fontAwesome" in ' . WWW_ROOT);
         }
         CakeLog::info('Cloning FontAwesome...</info>');
         exec('git clone git://github.com/FortAwesome/Font-Awesome ' . $fontAwesomePath);
     }
     chdir($fontAwesomePath);
     exec('git checkout -f master');
     $targetPath = WWW_ROOT . 'font' . DS;
     $Folder = new Folder($targetPath, true);
     $fontPath = WWW_ROOT . 'fontAwesome' . DS . 'font';
     $Folder = new Folder($fontPath);
     $files = $Folder->read();
     if (empty($files[1])) {
         CakeLog::error('No font files found');
         $this->_stop();
     }
     foreach ($files[1] as $file) {
         $File = new File($fontPath . DS . $file);
         $newFile = $targetPath . $file;
         if ($File->copy($newFile)) {
             $text = __('Font: %s copied', $file);
             CakeLog::info($text);
         } else {
             $text = __('File: %s not copied', $file);
             CakeLog::error($text);
         }
     }
 }
예제 #13
0
 /**
  * Set authenticator
  *
  * @return void
  **/
 private function __setDefaultAuthenticator()
 {
     $plugin = Inflector::camelize($this->request->offsetGet('plugin'));
     $scheme = strtr(Inflector::camelize($this->request->offsetGet('plugin')), array('Auth' => ''));
     $callee = array(sprintf('Auth%sAppController', $scheme), '_getAuthenticator');
     if (is_callable($callee)) {
         $authenticator = call_user_func($callee);
         $this->Auth->authenticate = array($authenticator => array());
         CakeLog::info(sprintf('Will load %s authenticator', $authenticator), true);
     } else {
         CakeLog::info(sprintf('Unknown authenticator %s.%s', $plugin, $scheme), true);
     }
 }
예제 #14
0
 public function cardUpdate($data, $fields = null)
 {
     Stripe::setApiKey($this->key);
     $error = null;
     try {
         $customer = Stripe_Customer::retrieve($data['customer_id']);
         //update card
         $customer->source = $data['stripeToken'];
         $customer->save();
     } catch (Stripe_CardError $e) {
         $body = $e->getJsonBody();
         $err = $body['error'];
         CakeLog::error('Customer::Stripe_CardError: ' . $err['type'] . ': ' . $err['code'] . ': ' . $err['message'], 'stripe');
         $error = $err['message'];
     } catch (Stripe_InvalidRequestError $e) {
         $body = $e->getJsonBody();
         $err = $body['error'];
         CakeLog::error('Customer::Stripe_InvalidRequestError: ' . $err['type'] . ': ' . $err['message'], 'stripe');
         $error = $err['message'];
     } catch (Stripe_AuthenticationError $e) {
         CakeLog::error('Customer::Stripe_AuthenticationError: API key rejected!', 'stripe');
         $error = 'Payment processor API key error.';
     } catch (Stripe_ApiConnectionError $e) {
         CakeLog::error('Customer::Stripe_ApiConnectionError: Stripe could not be reached.', 'stripe');
         $error = 'Network communication with payment processor failed, try again later';
     } catch (Stripe_Error $e) {
         CakeLog::error('Customer::Stripe_Error: Stripe could be down.', 'stripe');
         $error = 'Payment processor error, try again later.';
     } catch (Exception $e) {
         CakeLog::error('Customer::Exception: Unknown error.', 'stripe');
         $error = 'There was an error, try again later.';
     }
     if ($error !== null) {
         // an error is always a string
         return (string) $error;
     }
     CakeLog::info('Update Card: customer id ' . $customer->id, 'stripe');
     return $this->_formatResult($customer, $fields);
 }
예제 #15
0
 /**
  * Copy font files used by admin ui
  *
  * @throws Exception
  */
 protected function _copyFonts()
 {
     $croogoPath = CakePlugin::path('Croogo');
     $fontAwesomePath = $croogoPath . 'webroot' . DS . 'fontAwesome';
     if (!file_exists($fontAwesomePath)) {
         if (!$this->_clone) {
             throw new Exception('You don\'t have "fontAwesome" in ' . WWW_ROOT);
         }
         CakeLog::info('Cloning FontAwesome...');
         $command = sprintf('git clone -b %s %s %s', escapeshellarg($this->_tags['fontAwesome']), escapeshellarg($this->_repos['fontAwesome']), escapeshellarg($fontAwesomePath));
         CakeLog::info("\t{$command}");
         exec($command);
     }
     chdir($fontAwesomePath);
     exec(sprintf('git checkout -f %s', escapeshellarg($this->_tags['fontAwesome'])));
     $targetPath = $croogoPath . 'webroot' . DS . 'font' . DS;
     $Folder = new Folder($targetPath, true);
     $fontPath = $croogoPath . 'webroot' . DS . 'fontAwesome' . DS . 'font';
     $Folder = new Folder($fontPath);
     $files = $Folder->read();
     if (empty($files[1])) {
         CakeLog::error('No font files found');
         $this->_stop();
     }
     foreach ($files[1] as $file) {
         $File = new File($fontPath . DS . $file);
         $newFile = $targetPath . $file;
         $displayFilename = str_replace(APP, '', $newFile);
         if ($File->copy($newFile)) {
             $text = __d('croogo', 'Font: %s copied', $displayFilename);
             CakeLog::info($text);
         } else {
             $text = __d('croogo', 'File: %s not copied', $file);
             CakeLog::error($text);
         }
     }
 }
예제 #16
0
 public function info($message, array $context = array())
 {
     CakeLog::info($message, $context);
 }
예제 #17
0
 /**
  * コマンド実行結果をログに出力
  *
  * @param string $type タイプ `bower` or `migration`
  * @param array $messages コマンド実行結果
  * @return void
  */
 private function __commandOutputResults($type, $messages)
 {
     // Write logs
     //if (Configure::read('debug')) {
     foreach ($messages as $message) {
         CakeLog::info(sprintf('[' . $type . ']   %s', $message));
     }
     //}
 }
예제 #18
0
 /**
  * test convenience methods
  *
  * @return void
  */
 public function testConvenienceMethods()
 {
     $this->_deleteLogs();
     CakeLog::config('debug', array('engine' => 'File', 'types' => array('notice', 'info', 'debug'), 'file' => 'debug'));
     CakeLog::config('error', array('engine' => 'File', 'types' => array('emergency', 'alert', 'critical', 'error', 'warning'), 'file' => 'error'));
     $testMessage = 'emergency message';
     CakeLog::emergency($testMessage);
     $contents = file_get_contents(LOGS . 'error.log');
     $this->assertRegExp('/(Emergency|Critical): ' . $testMessage . '/', $contents);
     $this->assertFalse(file_exists(LOGS . 'debug.log'));
     $this->_deleteLogs();
     $testMessage = 'alert message';
     CakeLog::alert($testMessage);
     $contents = file_get_contents(LOGS . 'error.log');
     $this->assertRegExp('/(Alert|Critical): ' . $testMessage . '/', $contents);
     $this->assertFalse(file_exists(LOGS . 'debug.log'));
     $this->_deleteLogs();
     $testMessage = 'critical message';
     CakeLog::critical($testMessage);
     $contents = file_get_contents(LOGS . 'error.log');
     $this->assertContains('Critical: ' . $testMessage, $contents);
     $this->assertFalse(file_exists(LOGS . 'debug.log'));
     $this->_deleteLogs();
     $testMessage = 'error message';
     CakeLog::error($testMessage);
     $contents = file_get_contents(LOGS . 'error.log');
     $this->assertContains('Error: ' . $testMessage, $contents);
     $this->assertFalse(file_exists(LOGS . 'debug.log'));
     $this->_deleteLogs();
     $testMessage = 'warning message';
     CakeLog::warning($testMessage);
     $contents = file_get_contents(LOGS . 'error.log');
     $this->assertContains('Warning: ' . $testMessage, $contents);
     $this->assertFalse(file_exists(LOGS . 'debug.log'));
     $this->_deleteLogs();
     $testMessage = 'notice message';
     CakeLog::notice($testMessage);
     $contents = file_get_contents(LOGS . 'debug.log');
     $this->assertRegExp('/(Notice|Debug): ' . $testMessage . '/', $contents);
     $this->assertFalse(file_exists(LOGS . 'error.log'));
     $this->_deleteLogs();
     $testMessage = 'info message';
     CakeLog::info($testMessage);
     $contents = file_get_contents(LOGS . 'debug.log');
     $this->assertRegExp('/(Info|Debug): ' . $testMessage . '/', $contents);
     $this->assertFalse(file_exists(LOGS . 'error.log'));
     $this->_deleteLogs();
     $testMessage = 'debug message';
     CakeLog::debug($testMessage);
     $contents = file_get_contents(LOGS . 'debug.log');
     $this->assertContains('Debug: ' . $testMessage, $contents);
     $this->assertFalse(file_exists(LOGS . 'error.log'));
     $this->_deleteLogs();
 }
예제 #19
0
 /**
  * Install migrations
  *
  * @param array $plugins Migration plugins
  * @return bool Install succeed or not
  * @author Jun Nishikawa <*****@*****.**>
  **/
 private function __installBowerPackages($plugins)
 {
     // Invoke all available bower
     foreach ($plugins as $plugin) {
         $pluginPath = ROOT . DS . 'app' . DS . 'Plugin' . DS . Inflector::camelize($plugin) . DS;
         if (!file_exists($pluginPath . 'bower.json')) {
             continue;
         }
         $file = new File($pluginPath . 'bower.json');
         $bower = json_decode($file->read(), true);
         $file->close();
         foreach ($bower['dependencies'] as $package => $version) {
             CakeLog::info(sprintf('[bower] Start bower install %s#%s for %s', $package, $version, $plugin));
             $messages = array();
             $ret = null;
             exec(sprintf('cd %s && `which bower` --allow-root install %s#%s --save', ROOT, $package, $version), $messages, $ret);
             // Write logs
             if (Configure::read('debug')) {
                 foreach ($messages as $message) {
                     CakeLog::info(sprintf('[bower]   %s', $message));
                 }
             }
             CakeLog::info(sprintf('[bower] Successfully bower install %s#%s for %s', $package, $version, $plugin));
         }
     }
     return true;
 }
예제 #20
0
 public function delete($id = null)
 {
     if (AuthComponent::user('role') != 'admin') {
         throw new ForbiddenException("You're now allowed to do this.");
     }
     $this->User->id = $id;
     if (!$this->User->exists()) {
         throw new NotFoundException(__('Invalid user'));
     }
     if ($this->User->delete()) {
         # Store log
         CakeLog::info('The user ' . AuthComponent::user('username') . ' (ID: ' . AuthComponent::user('id') . ') deleted user (ID: ' . $this->User->id . ')', 'users');
         $this->Session->setFlash(__('User deleted'), 'flash_success');
         $this->redirect(array('action' => 'index'));
     }
     $this->Session->setFlash(__('User was not deleted'), 'flash_fail');
     $this->redirect(array('action' => 'index'));
 }
예제 #21
0
 /**
  * Handle action when receive direct payment callback
  *
  */
 public function handle_direct_pay()
 {
     $this->loadModel('UserProfile');
     $this->layout = 'ajax_with_css';
     $this->set('title_for_layout', 'お支払い');
     // Get callback data
     $callback = $this->request->query;
     // Write log
     CakeLog::info(print_r($callback, true), 'payment');
     if (isset($callback['rst']) && $callback['rst'] === '1' && (isset($callback['g_security']) && $callback['g_security'] === $this->Session->read('Credit.security_code'))) {
         $this->Session->delete('Credit.security_code');
         $this->Session->write('Credit.amount', $callback['ta']);
         $success = true;
         $paymentTransactionCode = isset($callback['gid']) && $callback['gid'] ? $callback['gid'] : '';
         $paymentErrorCode = $callback['ec'];
         $paymentDatetime = $callback['g_payment_date'];
         // Save payment information
         $this->UserProfile->save(array('id' => $this->Auth->user('id'), 'payment_store_code' => isset($callback['cod']) && $callback['cod'] ? $callback['cod'] : '', 'payment_transaction_code' => isset($callback['gid']) && $callback['gid'] ? $callback['gid'] : '', 'payment_datetime' => $callback['g_payment_date']));
         $this->set(compact('success', 'paymentTransactionCode', 'paymentErrorCode', 'paymentDatetime'));
     } else {
         // Save payment information
         $this->UserProfile->save(array('id' => $this->Auth->user('id'), 'payment_error_code' => $callback['ec'], 'payment_error_datetime' => $callback['g_payment_date']));
         $this->redirect(array('action' => 'direct_pay_error', '?' => $callback));
     }
 }