Jump to content

MartyIX

Members
  • Posts

    15
  • Joined

  • Last visited

  • Days Won

    1

MartyIX last won the day on March 30 2014

MartyIX had the most liked content!

MartyIX's Achievements

Newbie

Newbie (1/14)

3

Reputation

  1. Hello, Blesta has its own mechanism for displaying errors. It is part of minPHP framework and the relevant files are /lib/stdlib.php and /lib/unknown_exception.php. However, there are PHP libraries that can help you further to ease development in PHP. I like https://packagist.org/packages/tracy/tracy (see an example here: http://examples.nette.org/ndebug/nette-exception.html) Advantages Tracy has a production mode (useful for production version of Blesta when you want to log exceptions and other errors to files) and a develoment mode (useful for plugin developers, maybe even Blesta developers). Development mode allows you to see stack trace, parameters and much more (see http://examples.nette.org/ndebug/nette-exception.html) You can catch all unhandled exceptions. You can event catch NOTICE errors (I believe that everybody should do that.) If an error occurs you have a log file to examine. How to make it work in Blesta 1) Composer settings (composer.json) { "config": { "vendor-dir": "vendors" }, "require": { "tracy/tracy": "dev-master" } } 2) Create folder /log (in Blesta folder) 3) Update /index.php <?php /* SVN FILE: $Id: index.php 52 2010-10-01 20:50:08Z cody $ */ /** * This file transfers control over to the dispatcher which will invoke the * appropriate controller. We also handle any exceptions that were not handled * elsewhere in the application, so we can end gracefully. * * @package minPHP * @version $Revision: 52 $ * @modifiedby $LastChangedBy: cody $ * @lastmodified $Date: 2010-10-01 13:50:08 -0700 (Fri, 01 Oct 2010) $ */ $start = microtime(true); include __DIR__ . '/vendors/autoload.php'; include __DIR__ . '/vendors/Logger/Logger.php'; // my logging class containing \BlestaLogger (it has nothing to do with Tracy) \BlestaLogger::create(); \BlestaLogger::addDebug("==== REQUEST START ===="); //try { include(dirname(__FILE__) . "/lib/init.php"); // Start Tracy // Note: Error handlers are registered in lib/init.php. Tracy does the same therefore // Tracy needs to be initalized after init.php to overwrite previous behaviour) $serverName = isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : ""; $productionMode = php_sapi_name() === 'cli' || stripos($serverName, '.local') === false; $logDir = __DIR__ . '/log'; \Tracy\Debugger::$strictMode = true; \Tracy\Debugger::$scream = true; \Tracy\Debugger::$onFatalError = "\UnknownException::setFatalErrorHandler"; \Tracy\Debugger::enable($productionMode, $logDir); // Dispatch the Web request if (!empty($_SERVER['REQUEST_URI'])) Dispatcher::dispatch($_SERVER['REQUEST_URI']); // Dispatch the CLI request else Dispatcher::dispatchCli($argv); //} /*catch (Exception $e) { try { // Attempt to raise any error, gracefully Dispatcher::raiseError($e); } catch (Exception $e) { if (Configure::get("System.debug")) echo $e->getMessage() . " on line <strong>" . $e->getLine() . "</strong> in <strong>" . $e->getFile() . "</strong>\n" . "<br />Printing Stack Trace:<br />" . nl2br($e->getTraceAsString()); else echo $e->getMessage(); } }*/ \BlestaLogger::addDebug("==== REQUEST END ===="); $end = microtime(true); // Display rendering time if benchmarking is enabled if (Configure::get("System.benchmark")) echo "execution time: " . ($end-$start) . " seconds"; ?> Feature request If you like Tracy (please note that I'm not affiliated with the library in any way) maybe you can integrate it into Blesta. Have a nice day!
  2. The developer manual is very brief in this regard. It would definitely help others. Could you please confirm that whether I did the event registration in triggerEvent function above correctly or not? The thing is that sometime I need to adjust Blesta and events represent the least invasive way how to that.
  3. Hola, I'm trying to add a new event to getEvents() method in my plugin. To my surprise the method is not called. I suspect that Blesta caches the data somewhere as a part of a plugin installation process. Am I right? Or am I missing something? <?php class MyPluginPlugin extends Plugin { ... public function getEvents() { // THIS METHOD IS NOT CALLED. I CHECKED BY ADDING A LOGGING STATEMENT HERE. return array( array( 'event' => "Appcontroller.preAction", 'callback' => array("this", "run") ), array( 'event' => "Another.event", 'callback' => array("this", "anotherEvent") ) ); } public function run($event) { // This will execute when the "Appcontroller.preAction" event is triggered } } ?> Source: http://docs.blesta.com/display/dev/Plugin+Events Thanks! EDIT: I tried my idea with installation of the plugin and the method was really called. So that seems to be the culprit. EDIT2: I could have just have a look at plugin_manager.php file... EDIT3: This seems to work: Event registration in /plugins/my_plugin_name/my_plugin_plugin.php (see http://docs.blesta.com/display/dev/Plugin+Events): public function getEvents() { return array( array( 'event' => "Invoices.add", 'callback' => array("this", "invoiceAdded") ) ); } public function invoiceAdded($event) { \BlestaLogger::addDebug("plugins/my_plugin_plugin/Plugin::invoiceAdded(event)", [$event]); \BlestaLogger::addDebug("plugins/my_plugin_plugin/Plugin::invoiceAdded(): TODO - call a method in NettAccounts model"); \BlestaLogger::addDebug("plugins/my_plugin_plugin/Plugin::invoiceAdded(-)"); } Sample controller /plugins/my_plugin_name/Controllers/InvoiceTester.php: class InvoiceTester extends AppController { /** * @link https://shop.example.com/plugin/yourPluginName/InvoiceTester/triggerEvent/ * @return void */ public function triggerEvent() { \BlestaLogger::addDebug("plugins/yourPluginName/controllers/InvoiceTester::triggerEvent()"); Loader::loadComponents($this, array("Events")); $this->Events->register("Invoices.add", array("EventCallback", "triggerPluginEvent")); $event = new \EventObject("Invoices.add", array('foo' => 'bar')); $this->Events->trigger($event); \BlestaLogger::addDebug("plugins/yourPluginName/controllers/InvoiceTester::triggerEvent(-)"); } }
  4. Hello, I'm trying to show some information based on the payment method(e.g. Paypal; maybe a better word is "gateway") that a customer chose when he/she bought a product. Can I do that? Thanks P.S. There is a slight complication that it may very well happen that an invoice is paid by several transactions (I believe that Blesta handles that after I checked source codes.) ______________ I examined Blesta's source codes and it works with transactions and invoices. I found the database tables: invoices, transactions and transaction_types. However, I don't see any connection between a transaction and a gateway. So it seems that Blesta does not record this type of information.
  5. MartyIX

    $_Get Not Work

    You can see in lib/dispatcher.php the line: $ctrl->get = $_get; so that you can use the following line in your controller $this->get['parameter'] as an equivalent of $_GET['parameter'] HTH
  6. I see. Can you tell me when you expect (weeks/months/...) to release Blesta 3.1? It would help me to plan my time accordingly.
  7. Hello, I'm trying to show an exchange rate on an invoice. The exchange rate should be from the time when the invoice was processed by Blesta (i.e. sent to the customer). Can I do that in Blesta? Or can I adjust Blesta somehow to achieve the described behaviour? Thanks!
  8. Paul: This is not an issue of your dedication to fix issues. The issue was resolved very fast, thank you for that. Yet, a unit test is a cheap way how to assure that Blesta still works with minimal amount of work. The source code seems in good shape to create a unit test, so I don't see a reason why there should NOT be a unit test to avoid troubles like this.
  9. Hello, I examined Google Finance exchange rate processor (/components/exchange_rates/google_finance/google_finance.php) and it seems that it no longer works because the URL http://www.google.com/ig/calculator is not working any more. I believe that it was shutted down together with iGoogle by Google. Could anybody confirm this? Thank you! Blesta version: 3.0.6
  10. There are only Users.login and Users.logout events and the events will be available in Blesta 3.1. I don't believe that events can solve my problem because I want to sign a user in via a form in my project (where there are no Blesta events).
  11. Hello, I can set Invoice Format on page /admin/settings/company/billing/customization/ (in my case it is: {year}Company{num}). I would like to pad invoice IDs with zeros. I guess that for this purpose there is inv_pad_size setting (http://docs.blesta.com/display/dev/Company+Settings). However, I was not able to make it work - id_code of invoice is 2013Company1 instead of 2013Company0001. Is it a bug? Or what is the purpose of the inv_pad_size setting? /app/models/invoices.php (This may be the place where inv_pad_size is not taken into account) /** * Partially constructs the query required by Invoices::get() and others * * @param int $invoice_id The ID of the invoice to fetch * @return Record The partially constructed query Record object */ private function getInvoice($invoice_id) { $fields = array("invoices.*", "REPLACE(invoices.id_format, ?, invoices.id_value)" => "id_code", "invoice_delivery.date_sent" => "delivery_date_sent" ); // Fetch the invoices along with total due and total paid, calculate total remaining on the fly $this->Record->select($fields)->select(array("invoices.total-IFNULL(invoices.paid,0)"=>"due"), false)-> appendValues(array($this->replacement_keys['invoices']['ID_VALUE_TAG']))-> from("invoices")-> on("invoice_delivery.date_sent", "!=", null)->leftJoin("invoice_delivery", "invoice_delivery.invoice_id", "=", "invoices.id", false)-> where("invoices.id", "=", $invoice_id)-> group("invoices.id"); return $this->Record; } Thank you!
  12. Hello, I'm trying to integrate Blesta to my project and I would like to know if I'm doing it correctly. Setup: http://www.example.com -- my project https://shop.example.com -- Blesta location (v3.0.5) Problem: I need to share information about the user who is signed in so that the currently signed in user can buy something via Blesta and he can also do some actions in my project. A user should sign in only once to be signed in my project and in Blesta at the same time. Difficulties: 1) First problem is that Blesta and my project both uses SESSIONs. Resolution: I disabled in Blesta/Components/session/session.php (see the change below) some code that setup sessions to use database (it means that file storage is used for sessions now) I set session.cookie-domain to ".example.com" so that the session cookie is shared among ALL subdomains of example.com (i.e. www.example.com and shop.example.com) and therefore I can work with the same $_SESSION array in Blesta and in my project. 2) Sign a user in Blesta and my project at the same time in MyProject/User/Login.php Resolution: I changed authentication in my project to use Blesta API to verify credentials (please see MyProject/User/Login.php source code below) where I set two SESSION variables: $_SESSION['blesta_id'] = $user->id; and $_SESSION['blesta_client_id'] = $client->id; (Is it OK? Or should I set more variables in $_SESSION array?) The second step (that I didn't solve yet) is to redirect to my login page (http://www.example.com/user/login) whenever a user visits https://shop.example.com/client/login/. Question Is this correct way how to share login information between a custom made project and Blesta? Source codes: MyProject/User/Login.php (not Blesta!) <?php public function authenticate(array $credentials) { Logger::addDebug("Project\User\LoginModel::authenticate(credentials: >>>)", [$credentials]); $email = $credentials[self::USERNAME]; $password = $credentials[self::PASSWORD]; $user = $this->getContainer()->parameters['blesta']['api']['user']; $key = $this->getContainer()->parameters['blesta']['api']['key']; $url = $this->getContainer()->parameters['blesta']['api']['url']; $verifySSL = $this->getContainer()->parameters['blesta']['api']['verifySSL']; // https://github.com/phillipsdata/blesta_sdk/tree/master/api (BlestaApi class) $api = new \BlestaApi($url, $user, $key, $verifySSL); # # Retrieve user # Logger::addDebug("Project\User\LoginModel::authenticate(): Issuing users::getByUsername request on Blesta"); $response = $api->get("users", "getByUsername", array('username' => $email)); if ($response->errors()) { Logger::addError("Project\User\LoginModel::authenticate(): getByUsername failed", [$response->errors()]); Logger::notify(10, "users::getByUsername: \$response->errors(): " . var_export($response, true)); throw new Project\Security\AuthenticationException("Invalid server error.", self::NOT_APPROVED); } $user = $response->response(); // $user is an array like this: // ["id"]=> string(1) "5" // ["username"]=> string(25) "some-username (e.g. somebody@example.com" // ["password"]=> string(60) "some-pasword" // ["two_factor_mode"]=> string(4) "none" // ["two_factor_key"]=> NULL // ["two_factor_pin"]=> NULL // ["date_added"]=> string(19) "2013-10-04 09:18:55" if (!$user) { Logger::addError("Project\User\LoginModel::authenticate(): User was not found.", [$user]); throw new Project\Security\AuthenticationException("The account does not exist.", self::IDENTITY_NOT_FOUND); } # # Check password # Logger::addDebug("Project\User\LoginModel::authenticate(): Issuing 'users::checkPassword' request on Blesta"); $response = $api->get("users", "checkPassword", array('password' => $password, 'stored_hash' => $user->password)); if ($response->errors()) { Logger::addError("Project\User\LoginModel::authenticate(): checkPassword failed", [$response->errors()]); Logger::notify(10, "users::checkPassword: \$response->errors(): " . var_export($response, true)); throw new Project\Security\AuthenticationException("Invalid server error.", self::NOT_APPROVED); } $isCorrectPassword = $response->response(); Logger::addDebug("Project\User\LoginModel::authenticate(): Is password correct for ID #{$user->id}? ", [$isCorrectPassword]); if ($isCorrectPassword !== true) { Logger::addDebug("Project\User\LoginModel::authenticate(): Password is NOT correct!", [$isCorrectPassword]); throw new Project\Security\AuthenticationException("The combination of email and password is not right.", self::NOT_APPROVED); } Logger::addDebug("Project\User\LoginModel::authenticate(): Username and password are CORRECT!"); # # Retrieve client # Logger::addDebug("Project\User\LoginModel::authenticate(): Issuing 'clients::getByUserId' request on Blesta"); $response = $api->get("clients", "getByUserId", array('user_id' => $user->id)); if ($response->errors()) { Logger::addError("Project\User\LoginModel::authenticate(): clients::getByUserId failed", [$response->errors()]); Logger::notify(10, "clients::getByUserId: \$response->errors(): " . var_export($response, true)); throw new Project\Security\AuthenticationException("Invalid server error.", self::NOT_APPROVED); } $client = $response->response(); if (!$client) { Logger::addWarning("Project\User\LoginModel::authenticate(): No client is assignd to the account!", [$client]); throw new Project\Security\AuthenticationException("No client is assignd to the account.", self::NOT_APPROVED); } $_SESSION['blesta_id'] = $user->id; $_SESSION['blesta_client_id'] = $client->id; $user = (array)$user; Logger::addDebug("Project\User\LoginModel::authenticate(): Providing identity", [$user]); Logger::addDebug("Project\User\LoginModel::authenticate(-)"); return $user; } Blesta/Components/session/session.php private function sessionSet($ttl, $tbl, $tblid, $tblexpire, $tblvalue, $session_name) { $this->ttl = $ttl; $this->tbl = $tbl; $this->tblid = $tblid; $this->tblexpire = $tblexpire; $this->tblvalue = $tblvalue; if (Session::$instances == 0) { // session_name($session_name); // session_set_save_handler( // array(&$this, "sessionOpen"), // array(&$this, "sessionClose"), // array(&$this, "sessionSelect"), // array(&$this, "sessionWrite"), // array(&$this, "sessionDestroy"), // array(&$this, "sessionGarbageCollect") // ); // // If a cookie is available, attempt to use that session and reset // // the ttl to use the cookie ttl, but only if we don't have a current session cookie as well // if (isset($_COOKIE[Configure::get("Session.cookie_name")]) && !isset($_COOKIE[session_name()])) { // if ($this->setKeepAlive($_COOKIE[Configure::get("Session.cookie_name")])) { // $this->setCsid($_COOKIE[Configure::get("Session.cookie_name")]); // $this->ttl = Configure::get("Session.cookie_ttl"); // } // } // elseif (isset($_COOKIE[Configure::get("Session.cookie_name")]) && isset($_COOKIE[session_name()]) && $_COOKIE[Configure::get("Session.cookie_name")] == $_COOKIE[session_name()]) { // $this->ttl = Configure::get("Session.cookie_ttl"); // } // Start the session session_start(); } Session::$instances++; }
  13. Hello, I try to implement a plugin that would integrate Blesta with our system and I would like to use callbacks: "Users.login" and "Users.logout" (http://docs.blesta.com/display/dev/Event+Handlers). I tried to register these two events as follows: class MyPlugin extends Plugin { ... public function getEvents() { return array( array( 'event' => "Appcontroller.preAction", 'callback' => array("this", "run") ), array( 'event' => "Users.login", 'callback' => array("this", "userWasLoggedIn"), ), array( 'event' => "Users.logout", 'callback' => array("this", "userWasLoggedOut") ) ); } // This method IS called. public function run($event) { echo "run -- method"; } // This method is NOT called. public function userWasLoggedIn($event) { var_dump("in", $event); throw new \Excepion("aaa"); } // This method is NOT called. public function userWasLoggedOut($event) { var_dump("out", $event); throw new \Excepion("sss"); } } The problem is that the methods userWasLoggedIn and userWasLoggedOut are not called when a user submits form located at https://blesta.domain.com/client/login/ http://docs.blesta.com/display/dev/Event+Handlers - I've just noticed that the events are available since version 3.1. Does it mean that the events will be available in the next release of Blesta? As far as I know the last released version is 3.0.5.
  14. Hello, is it possible to setup Blesta so that a customer can register to Blesta without making an order? I ask because I would like to add a link to registration on the webpage: https://blesta.company.com/client/login/ Thank you! EDIT: I have already found how to do it. But I do not know how to delete this thread.
  15. Hello guys, Describe the issue you're experiencing. + Provide detailed steps necessary to reproduce the issue. 1) A customer added a new ticket to Blesta with some text (no text formatting) 2) Being a department manager I received an email with the text from the customer. 3) I replied via gmail.com (a single sentence, no text formatting) 4) I see in Blesta (/admin/plugin/support_manager/admin_tickets/reply/10/) some additional text that I did not write as the answer - it seems that the content of the email was not parsed correctly. The text that is superfluous is "On Sat ...". List any generated errors. (The "Oh Noes" error pages are very helpful.) N/A Include the URL the error occurred on, relative to the installation path, ie "/admin/login". /admin/plugin/support_manager/admin_tickets/reply/10/ Server: Windows Server 2008 R2 Datacenter Blesta 3.0.3 PHP Version 5.4.10 MySQL 5.5.29
×
×
  • Create New...