PHP code example of vetruvet / laravel-self-updater
1. Go to this page and download the library: Download vetruvet/laravel-self-updater library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
return array(
'routes' => array(
'manual' => '/trigger_update', // url for GET manual trigger DEFAULT: /trigger_update
'auto' => '/trigger_update', // url for POST automatic trigger DEFAULT: /trigger_update
'manual_filter' => null, // filter for manual trigger route (e.g. if you want to 'auth.admin' first) DEFAULT: <none>
),
'branch' => 'master', // branch to listen for pushes for and to pull from DEFAULT: master
'site_name' => null, // site name - used in various display functions DEFAULT: $_SERVER['SERVER_NAME']
'commit_hash_length' => 7, // length limit for commit hash (0 for full hash) DEFAULT: 0
//'email' => false, //false to disable email notifications
'email' => array(
// from info for notification email DEFAULT: as specified in app/config/mail.php; or <site_name> Self Updater <update@$_SERVER['SERVER_NAME']>
'from' => array('address' => '[email protected]', 'name' => 'Sample Self-Updater'),
'to' => '[email protected]', // target for notification email REQUIRED
'reply_to' => '[email protected]', // reply-to for notification email DEFAULT: <from>
//subject can be a static string, or a callback (or either split out into success/failure subject lines)
//'subject' => 'Self-Updater was triggered',
//'subject' => function($site_name, $success, $commit_hash) { return $site_name . ' Self-Updater ' . ($success ? 'Success: ' . $commit_hash : 'ERROR'); },
'subject' => array(
'success' => 'Self-Updater success', // can also be callback function like above
'failure' => 'Self-Updater failure',
),
),
);
Event::listen('self-updater.pre-update', function ($auto) {
// $auto: boolean whether update was triggered automatically through webhook (POST) or manually (GET)
//
// return false; // return false to cancel the update operation.
});
Event::listen('self-updater.post-update', function($success, $error, $auto, $git_commit_hash, $sent_email) {
// $success: boolean success or failure
// $error: error string if failure, empty string otherwise
// $auto: boolean whether update was triggered automatically through webhook (POST) or manually (GET)
// $git_commit_hash: new git commit hash if update was successful, empty string otherwise
// $sent_email: boolean whether or not a notification email was sent
});