### install() Source: https://docs.blesta.com/developers/messengers/messenger-methods The `install()` method is invoked when the messenger is installed. It should contain any logic required for the initial setup of the messenger. ```APIDOC ## install() ### Description Performs logic when the messenger is installed. ### Method Signature `public function install()` ### Example ```php class MyMessenger extends Messenger { ... public function install() { // Perform install logic } } ``` ``` -------------------------------- ### Implement Gateway Install Method Source: https://docs.blesta.com/developers/gateways/non-merchant-gateways This method is invoked during gateway installation to perform any necessary setup logic. It can check for dependencies or set errors if installation should not proceed. ```php class MyGateway extends NonmerchantGateway { ... public function install() { // Nothing to do } ... } ``` -------------------------------- ### install(), upgrade(), uninstall() Source: https://docs.blesta.com/developers/modules/module-methods These methods are invoked during the module's lifecycle: install() for initial setup, upgrade() for version updates, and uninstall() for removal. They are crucial for managing module-specific data, configurations, and dependencies like cron tasks. ```APIDOC ## install() ### Description Performs initial setup logic when the module is installed. This often includes creating necessary database entries, cron tasks, or other system configurations. ### Method `public function install()` ### Parameters None ### Request Example ```php public function install() { // ... install logic ... } ``` ## upgrade($current_version) ### Description Handles logic required when upgrading the module to a new version. This can include database schema changes, data migrations, or updating configurations. ### Method `public function upgrade($current_version)` ### Parameters - **current_version** (string) - The current installed version of the module. ### Request Example ```php public function upgrade($current_version) { // ... upgrade logic ... } ``` ## uninstall($module_id, $last_instance) ### Description Performs cleanup logic when the module is uninstalled. This typically involves removing module-specific data, cron tasks, and any other resources created during installation or upgrades. ### Method `public function uninstall($module_id, $last_instance)` ### Parameters - **module_id** (int) - The ID of the module instance being uninstalled. - **last_instance** (bool) - True if this is the last instance of the module being uninstalled, false otherwise. ### Request Example ```php public function uninstall($module_id, $last_instance) { // ... uninstall logic ... } ``` ``` -------------------------------- ### Plugin Install Logic Source: https://docs.blesta.com/developers/plugins/getting-started Implement the install() method in your plugin class to execute custom code when the plugin is installed. This is where you would place any setup logic. ```php ``` -------------------------------- ### Complete Event Example Source: https://docs.blesta.com/developers/events/creating-events A full example demonstrating event registration, triggering, and callback execution that outputs parameters. ```php getFromContainer('util.events'); $eventListener = $eventFactory->listener(); $eventListener->register('EventName', [$this, 'callbackMethod']); $eventListener->trigger($eventFactory->event('EventName', ['square', 'pink'])); return false; // don't render a view } public function callbackMethod($event) { $params = $event->getParams(); echo $params[0] . ' ' . $params[1]; // square pink } } ?> ``` -------------------------------- ### Complete Event Registration and Triggering Example Source: https://docs.blesta.com/developers/events/creating-events A full example demonstrating event registration, triggering, and callback execution within a controller. This example outputs 'square pink'. ```php Events->register("EventName", array($this, "callbackMethod")); $event = new EventObject("EventName", array("square", "pink")); $this->Events->trigger($event); return false; // don't render a view } public function callbackMethod(EventObject $event) { $params = $event->getParams(); echo $params[0] . " " . $params[1]; } } ?> ``` -------------------------------- ### Implement Gateway Install Logic Source: https://docs.blesta.com/developers/gateways/overview Place installation logic within the install() method of your gateway class. This method is invoked when the gateway is installed. ```php ``` -------------------------------- ### Sample Package Welcome Email Source: https://docs.blesta.com/integrations/modules/logicboxes This sample email can be used in the Package Welcome Email section to help you get started. Ensure content is entered in both HTML and Text sections. ```text Your new domain has been successfully registered! Domain: {service.domain-name} Thank you for your business! ``` -------------------------------- ### Implement Messenger Install Logic Source: https://docs.blesta.com/developers/messengers/overview Place installation logic within the `install()` method of your messenger class. This method can also return metadata to be stored in the database. ```php ``` -------------------------------- ### Install Blesta (Interactive Mode with Admin/License) Source: https://docs.blesta.com/installation Run this command for installations that include admin account creation and license activation. Update all placeholder values before execution. ```bash php ./index.php install -dbhost DATABASE_HOST -dbport DATABASE_PORT -dbname DATABASE_NAME -dbuser DATABASE_USER -dbpass DATABASE_PASS -hostname WEBSITE_HOSTNAME -docroot DOCUMENT_ROOT_PATH -domain DOMAIN -licensekey LICENSE_KEY -firstname FIRST_NAME -lastname LAST_NAME -email EMAIL -username USERNAME -password PASSWORD ``` -------------------------------- ### API Request Structure Example Source: https://docs.blesta.com/developers/api Illustrates the URL structure for making an API request, including domain, installation path, model, method, and format. If your server does not support .htaccess, include index.php in your URL. ```text https://yourdomain.com/installpath/api/users/get.json?user_id=1 ``` -------------------------------- ### install Source: https://docs.blesta.com/developers/gateways/non-merchant-gateways Invoked when the gateway is installed to perform any installation logic. Sets Input errors if the gateway should not be installed. ```APIDOC ## install() ### Description This method is invoked when the gateway is installed to perform any installation logic. For example, if the gateway requires any dependencies, you could check that those dependencies are met before the gateway is installed. If the gateway should not be installed, set Input errors. ### Method Internal (called during gateway installation) ### Parameters - None ### Request Example ```php // This method is typically implemented by the gateway itself and called by the system. // Example of how it might be called internally: // $gateway->install(); ``` ### Response - No direct return value. Errors are set via `Input::setErrors()` if installation should be prevented. ``` -------------------------------- ### Install, Upgrade, and Uninstall Module Logic Source: https://docs.blesta.com/developers/modules/module-methods Implement module installation, upgrade, and uninstallation logic. This includes setting up cron tasks during installation and cleaning them up during uninstallation. ```php class MyModule extends Module { ... public function install() { // Perform install logic, such as installing cron tasks Loader::loadModels($this, ['CronTasks']); // Retrieve the cron task if it already exists for another company $task = $this->CronTasks->getByKey('task_one', 'my_module', 'module'); if (!$task) { // Create the automation task $task = [ 'key' => 'task_one', // a string used to identify this cron task (see MyPluginPlugin::cron()) 'task_type' => 'module', // this cron task is for a module, so it must be set to 'module' 'dir' => 'my_module', // the directory of this module 'name' => 'My Module Task', // the name of this cron task 'description' => 'This cron tasks does stuff', // the description of this task 'type' => 'time' // "time" = once per day at a defined time, "interval" = every few minutes or hours ]; $task_id = $this->CronTasks->add($task); } else { $task_id = $task->id; } // Create the cron task run for this company if ($task_id) { $task_run = array( 'time' => '14:25', // the daily 24-hour time that this task should run (optional, required if interval is not given) // 'interval' => '15', // the interval, in minutes, that this cron task should run (optional, required if time is not given) 'enabled' => 1, // 1 if this cron task is enabled, 0 otherwise (optional, default 1) ); $this->CronTasks->addTaskRun($task_id, $task_run); } } public function upgrade($current_version) { // Perform upgrade logic } public function uninstall($module_id, $last_instance) { // Perform uninstall logic, such as deleting cron tasks Loader::loadModels($this, ['CronTasks']); // Retrieve the cron task run for this company $cron_task_run = $this->CronTasks->getTaskRunByKey('task_one', 'my_module', false, 'module'); if ($last_instance) { // Delete all trace of this module, such as cron tasks // Remove the cron task altogether $cron_task = $this->CronTasks->getByKey('task_one', 'my_module', 'module'); if ($cron_task) { $this->CronTasks->deleteTask($cron_task->id, 'module', 'my_module'); } } // Remove individual task run if ($cron_task_run) { $this->CronTasks->deleteTaskRun($cron_task_run->task_run_id); } } ... } ``` -------------------------------- ### GET Request Example with cURL Source: https://docs.blesta.com/developers/api Example of making a GET request to the Blesta API using cURL, including necessary authentication headers. ```APIDOC ## GET /api/users/get.json ### Description Retrieves user information. ### Method GET ### Endpoint `https://yourdomain.com/api/users/get.json?user_id=1` ### Parameters #### Query Parameters - **user_id** (integer) - Required - The ID of the user to retrieve. ### Request Headers - **BLESTA-API-USER**: YOUR_API_USER_HERE - **BLESTA-API-KEY**: YOUR_API_KEY_HERE ### Request Example ```bash curl -X GET "https://yourdomain.com/api/users/get.json?user_id=1" \ -H "BLESTA-API-USER: YOUR_API_USER_HERE" \ -H "BLESTA-API-KEY: YOUR_API_KEY_HERE" ``` ``` -------------------------------- ### GET Request Example in PHP Source: https://docs.blesta.com/developers/api Example of making a GET request to the Blesta API using PHP's cURL functions, including authentication headers. ```APIDOC ## GET Request Example in PHP ### Description Demonstrates how to perform a GET request to the Blesta API using PHP and cURL, with header-based authentication. ### Code Example ```php ``` ``` -------------------------------- ### Setup Event Listener Source: https://docs.blesta.com/developers/events/creating-events Instantiate an EventFactory and retrieve a listener instance. This can be done by accessing the container or by directly instantiating the factory. ```php // Code that inherits from AppController or AppModel may retrieve an instance of the \Blesta\Core\Util\Events\EventFactory from the container by calling $this->getFromContainer('util.events') $eventFactory = $this->getFromContainer('util.events'); $eventListener = $eventFactory->listener(); // If you are working in a location that does not inherit from AppController or AppModel, you can load the \Blesta\Core\Util\Events\EventFactory yourself $eventFactory = new \Blesta\Core\Util\Events\EventFactory(); $eventListener = $eventFactory->listener(); ``` -------------------------------- ### PHP SDK Remote Connection Example Source: https://docs.blesta.com/developers/api Example demonstrating how to connect to the Blesta API remotely using the PHP SDK and make a GET request. ```php get("users", "get", array('user_id' => 1)); print_r($response->response()); print_r($response->errors()); ?> ``` -------------------------------- ### Example of Displayed Name Servers Source: https://docs.blesta.com/integrations/modules/cyberpanel This is how the name servers will be displayed in the welcome email after processing the loop. ```text Name server: ns1.domain.com Name server: ns2.domain.com ``` -------------------------------- ### cURL GET Request with API Key Authentication Source: https://docs.blesta.com/developers/api Example of making a GET request to the Blesta API using cURL with header-based API key authentication. ```bash curl -X GET "https://yourdomain.com/api/users/get.json?user_id=1" \ -H "BLESTA-API-USER: YOUR_API_USER_HERE" \ -H "BLESTA-API-KEY: YOUR_API_KEY_HERE" ``` -------------------------------- ### PHP GET Request with API Key Authentication Source: https://docs.blesta.com/developers/api Example of making a GET request to the Blesta API using PHP cURL with header-based API key authentication. ```php ``` -------------------------------- ### Implement getSettings() Method Source: https://docs.blesta.com/developers/gateways/non-merchant-gateways Implement getSettings() to return HTML content for the gateway's management page, used for entering API credentials. ```php class MyGateway extends NonmerchantGateway { ... public function getSettings(array $meta=null) { $this->currency = $currency; } ... } ``` -------------------------------- ### Sample VPS.NET Welcome Email Source: https://docs.blesta.com/integrations/modules/vpsnet This sample email content can be used in the Package Welcome Email section. Ensure content is provided for both HTML and Text sections. It includes placeholders for service-specific details. ```text Thank you for ordering your VPS, details below: Hostname: {service.vpsdotnet_hostname} IP Address: {service.vpsdotnet_primary_ip_address} Username: root Password: {service.vpsdotnet_password} Thank you for your business! ``` -------------------------------- ### Run Blesta CLI Installer Interactively Source: https://docs.blesta.com/installation Execute the Blesta Command Line Interface (CLI) installer in interactive mode. This command initiates the setup process, prompting you for necessary details during installation. It may require the full path to your PHP executable. ```bash php ./index.php install ``` -------------------------------- ### Get Credit API Response Source: https://docs.blesta.com/developers/resellers/reseller-api Example JSON response when successfully fetching the available credit. ```json { "response": 50.25 } ``` -------------------------------- ### Launch Blesta Upgrader (Command Line) Source: https://docs.blesta.com/upgrade Execute this command in the shell to start the Blesta upgrade process after uploading the files. Follow the on-screen instructions. ```bash php ./index.php admin/upgrade ``` -------------------------------- ### Get Packages API Response Source: https://docs.blesta.com/developers/resellers/reseller-api Example JSON response containing a list of available reseller packages. ```json { "response":[ { "id":"25", "name":"Blesta Monthly License", "description":"", "description_html":"", "qty":null, "id_code":"25", "pricing":[ { "id":"49", "term":"1", "period":"month", "price":"13.0000", "setup_fee":"0.0000", "cancel_fee":"0.0000", "currency":"USD" } ] }, { "id":"26", "name":"Blesta Owned License", "description":"", "description_html":"", "qty":null, "id_code":"26", "pricing":[ { "id":"32", "term":"0", "period":"onetime", "price":"95.0000", "setup_fee":"0.0000", "cancel_fee":"0.0000", "currency":"USD" } ] } ] } ``` -------------------------------- ### Sample Package Welcome Email Content Source: https://docs.blesta.com/integrations/modules/vultr This sample email content can be used in the Package Welcome Email section. It includes placeholders for dynamic server information. ```text Thanks for choosing us for your VPS! Your server {service.vultr_hostname} is now being spun up and you can manage it through our client area by clicking the "Manage" button next to the server on your Dashboard. The initial password can be found under the "Statistics" section. It may take a few minutes for the server to finish booting. ``` -------------------------------- ### Get Packages API Request with cURL Source: https://docs.blesta.com/developers/resellers/reseller-api Example cURL request to retrieve all available reseller packages. ```bash curl https://account.blesta.com/plugin/blesta_reseller/v2/index/getpackages.json -u USERNAME:PASSWORD ``` -------------------------------- ### Sample ISPConfig Package Welcome Email Source: https://docs.blesta.com/integrations/modules/ispconfig This sample email can be used in the Package Welcome Email section. It includes placeholders for domain, username, and password, as well as instructions for logging into ISPConfig and updating name servers. Ensure content is provided for both HTML and Text sections. ```html Thanks for choosing us for your web hosting needs! Domain: {service.ispconfig_domain} Username: {service.ispconfig_username} Password: {service.ispconfig_password} To log into ISPConfig please visit https://{module.host_name}:8080/login/ To make your site live, be sure to update your name servers to the following: {% for name_server in module.name_servers %} Name Server: {name_server}{% endfor %} Thank you for your business! ``` -------------------------------- ### Sample Package Welcome Email for CentOS Web Panel Source: https://docs.blesta.com/integrations/modules/centos-web-panel This sample email can be used in the Package Welcome Email section to provide clients with their hosting account details and control panel access information. Ensure content is entered in both HTML and Text sections. ```text Your hosting account details are below! Domain: {service.centoswebpanel_domain} Username: {service.centoswebpanel_username} Password: {service.centoswebpanel_password} To log into your control panel please visit https://{module.host_name}:2083. Please update your name servers as soon as possible to the following: {% for name_server in module.name_servers %} Name server: {name_server}{% endfor %} Thank you for your business ``` -------------------------------- ### Get Credit API Request with cURL Source: https://docs.blesta.com/developers/resellers/reseller-api Example cURL request to fetch the available credit using the Reseller API. ```bash curl https://account.blesta.com/plugin/blesta_reseller/v2/index/getcredit.json -u USERNAME:PASSWORD ``` -------------------------------- ### Implement Gateway Signup URL Method Source: https://docs.blesta.com/developers/gateways/non-merchant-gateways This method returns the URL for signing up with the gateway. If not defined, the signup URL from the configuration file will be used. ```php class MyGateway extends NonmerchantGateway { ... public function getSignupUrl() { return "https://domain.com/signup/"; } ... } ``` -------------------------------- ### Connecting Remotely with PHP SDK Source: https://docs.blesta.com/developers/api Example of using the Blesta API SDK in PHP to connect remotely and make a GET request. ```APIDOC ## Connecting Remotely with PHP SDK ### Description This example shows how to initialize the Blesta API SDK in PHP and make a GET request to retrieve user data. ### Code Example ```php get("users", "get", array('user_id' => 1)); print_r($response->response()); print_r($response->errors()); ?> ``` ``` -------------------------------- ### Sample Package Welcome Email Content Source: https://docs.blesta.com/integrations/modules/cyberpanel This content can be used in the Package Welcome Email section. It includes placeholders for account details and name servers. ```html Your hosting account details are below! Domain: {service.cyberpanel_domain} Username: {service.cyberpanel_username} Password: {service.cyberpanel_password} To log into your control panel please visit https://{module.host_name}:8090. Please update your name servers as soon as possible to the following: {% for name_server in module.name_servers %} Name server: {name_server}{% endfor %} Thank you for your business! ``` -------------------------------- ### Get Package Pricing ID Example Source: https://docs.blesta.com/integrations/plugins/license-manager Illustrates how to find the Package Pricing ID by inspecting HTML elements on the pricing table when editing a package. ```html