-
Notifications
You must be signed in to change notification settings - Fork 506
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge develop to master for 4.1.0 release
- Loading branch information
Showing
24 changed files
with
1,903 additions
and
580 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
FROM ushahidi/php-fpm-nginx:php-7.0 | ||
FROM ushahidi/php-fpm-nginx:php-7.1 | ||
|
||
WORKDIR /var/www | ||
COPY composer.json ./ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<?php | ||
|
||
namespace Ushahidi\App\Console\Commands; | ||
|
||
use Illuminate\Console\Command; | ||
|
||
use Ushahidi\App\Tools\OutputText; | ||
use Composer\Script\Event; | ||
use Composer\Installer\PackageEvent; | ||
|
||
class EnvironmentVerify extends Command | ||
{ | ||
|
||
/** | ||
* The console command name. | ||
* | ||
* @var string | ||
*/ | ||
protected $name = 'environment:verify'; | ||
|
||
/** | ||
* The console command description. | ||
* | ||
* @var string | ||
*/ | ||
protected $description = 'Verify the environment setup.'; | ||
protected $signature = 'environment:verify'; | ||
|
||
private static $NO_ENV = "No environment file found. Please copy the .env.example file to create a new .env file."; | ||
private static $REQUIRED_ENV_KEYS = [ | ||
"DB_CONNECTION" => "Please set `DB_CONNECTION=mysql` in the .env file.", | ||
"DB_HOST" => "Please set the address of your database in the DB_HOST key", | ||
"DB_PORT" => "Please set the port of your database in the DB_PORT key", | ||
"DB_DATABASE" => "Please set the name of your database in the DB_DATABASE key", | ||
"DB_USERNAME" => "Please set the username to connect to your database in the DB_USERNAME key", | ||
"DB_PASSWORD" => "Please set the password to connect to your database in the DB_PASSWORD key", | ||
"CACHE_DRIVER" => "Please set the CACHE_DRIVER according to your environment." . | ||
"See https://laravel.com/docs/5.8/cache#driver-prerequisites for more information on cache drivers.", | ||
"QUEUE_DRIVER" => "Please set the QUEUE_DRIVER according to your environment." . | ||
"See https://laravel.com/docs/5.8/queues for more information on queue drivers.", | ||
]; | ||
|
||
public static function verifyRequirements($console = true) | ||
{ | ||
$env = new \Ushahidi\App\PlatformVerifier\Env(); | ||
return $env->verifyRequirements(true); | ||
} | ||
|
||
public function verifyDB() | ||
{ | ||
$db = new \Ushahidi\App\PlatformVerifier\Database(); | ||
return $db->verifyRequirements(true); | ||
} | ||
/** | ||
* Execute the console command. | ||
* | ||
* @return void | ||
*/ | ||
public function handle() | ||
{ | ||
echo OutputText::info("Running ENV configuration checks"); | ||
|
||
$env = $this->verifyRequirements(true); | ||
|
||
echo OutputText::info("Running DB connectivity verification"); | ||
|
||
$db = $this->verifyDB(true); | ||
if (isset($db['errors'])||isset($env['errors'])) { | ||
throw new \Exception("Verification Failed."); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<?php | ||
|
||
/** | ||
* Ushahidi REST Base Controller | ||
* | ||
* @author Ushahidi Team <team@ushahidi.com> | ||
* @package Ushahidi\Application\Controllers | ||
* @copyright 2013 Ushahidi | ||
* @license https://www.gnu.org/licenses/agpl-3.0.html GNU Affero General Public License Version 3 (AGPL3) | ||
*/ | ||
|
||
namespace Ushahidi\App\Http\Controllers\API; | ||
|
||
use Ushahidi\App\Http\Controllers\RESTController; | ||
|
||
use Ushahidi\Factory\UsecaseFactory; | ||
use Illuminate\Http\Request; | ||
use Illuminate\Http\Response; | ||
use League\OAuth2\Server\Exception\OAuth2Exception; | ||
use League\OAuth2\Server\Exception\MissingAccessTokenException; | ||
use Ushahidi\App\Exceptions\ValidationException; | ||
use Ushahidi\App\Multisite\MultisiteManager; | ||
|
||
class VerifyController extends RESTController | ||
{ | ||
|
||
protected function getResource() | ||
{ | ||
return 'verifier'; | ||
} | ||
|
||
/** | ||
* @var array List of HTTP methods which may be cached | ||
*/ | ||
protected $cacheableMethods = []; | ||
|
||
/** | ||
* Get current api version | ||
*/ | ||
public static function version() | ||
{ | ||
return self::$version; | ||
} | ||
|
||
public function db(\Illuminate\Http\Request $request) | ||
{ | ||
if (!\Ushahidi\App\PlatformVerifier\DebugMode::isEnabled()) { | ||
return (new Response(null, 204)) | ||
->header('X-Ushahidi-Platform-Install-Debug-Mode', 'off'); | ||
} | ||
|
||
$output = new \Ushahidi\App\PlatformVerifier\Database(); | ||
return $output->verifyRequirements(false); | ||
} | ||
|
||
public function conf(\Illuminate\Http\Request $request) | ||
{ | ||
if (!\Ushahidi\App\PlatformVerifier\DebugMode::isEnabled()) { | ||
return (new Response(null, 204)) | ||
->header('X-Ushahidi-Platform-Install-Debug-Mode', 'off'); | ||
} | ||
|
||
$output = new \Ushahidi\App\PlatformVerifier\Env(); | ||
return $output->verifyRequirements(false); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
|
||
namespace Ushahidi\App\PlatformVerifier; | ||
|
||
use Ushahidi\App\Tools\OutputText; | ||
use Composer\Script\Event; | ||
use Composer\Installer\PackageEvent; | ||
use Illuminate\Support\Facades\DB as DB; | ||
|
||
use Ushahidi\App\Facades\Features; | ||
|
||
class Database | ||
{ | ||
private static $errors = [ | ||
// SQLSTATE[HY000] [2002] Connection refused | ||
'2002' => 'Check that your MySQL server is installed and running, ' . | ||
'and that the right DB_HOST and DB_PORT are set up in the .env file', | ||
'1049' => 'Check that the database in the .env file variable DB_DATABASE exists' . | ||
'and that the database user in DB_USERNAME has permissions to access it.', | ||
'1045' => 'Check that DB_USERNAME, DB_PASSWORD and DB_USERNAME are correct in the .env file. ' . | ||
'Verify that accessing mysql through a CLI with `mysql -u YOUR_DB_USERNAME -p ' . | ||
'YOUR_DB_NAME and entering the password on prompt results in a successful connection to mysql.' | ||
]; | ||
|
||
public function verifyRequirements(bool $console = true, \Illuminate\Database\MySqlConnection $connection = null) | ||
{ | ||
/* | ||
* Enable calling this with a mocked connection from unit tests, or using the regular class. | ||
* We can't inject it always because not everything that calls this has access to Illuminate\Support\Facades\DB | ||
*/ | ||
if (!$connection) { | ||
$connectTo = getenv('MULTISITE_DOMAIN') ? 'multisite' : 'mysql'; | ||
$connection = \Illuminate\Support\Facades\DB::connection($connectTo); | ||
} | ||
try { | ||
$connection = $connection->getPdo(); | ||
return Respond::successResponse('We were able to connect to the DB. Well done!', '', $console); | ||
} catch (\Exception $e) { | ||
$code = $e->getCode(); | ||
$explainer = isset(self::$errors[$code]) ? self::$errors[$code] : ''; | ||
$errors = [['message' => $e->getMessage(), 'explainer' => $explainer]]; | ||
return Respond::errorResponse($errors, $console); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<?php | ||
|
||
namespace Ushahidi\App\PlatformVerifier; | ||
|
||
use Ushahidi\App\Tools\OutputText; | ||
use Composer\Script\Event; | ||
use Composer\Installer\PackageEvent; | ||
|
||
# Methods to check whether the installation debug mode is enabled , as well | ||
# to create and delete the file that enables it | ||
# | ||
# This would be a nice as just commands in the composer.json file, | ||
# but that wouldn't be portable across platforms | ||
class DebugMode | ||
{ | ||
private static $SWITCH_FILE = "bootstrap/install_debug_mode.enabled"; | ||
private static $SWITCH_FILE_PATH = __DIR__ . "/../../bootstrap/install_debug_mode.enabled"; | ||
|
||
private static function getLastErrorMessage() | ||
{ | ||
$error = error_get_last(); | ||
if ($error === null) { | ||
return '[no PHP error]'; | ||
} else { | ||
return $error['message']; | ||
} | ||
} | ||
|
||
public static function isEnabled() | ||
{ | ||
return file_exists(self::$SWITCH_FILE_PATH) || | ||
($_ENV['USH_PLATFORM_INSTALL_DEBUG_MODE_ENABLED'] ?? null); | ||
} | ||
|
||
public static function enable() | ||
{ | ||
if (!file_exists(self::$SWITCH_FILE_PATH)) { | ||
// create the file | ||
if (touch(self::$SWITCH_FILE_PATH)) { | ||
echo OutputText::success(self::$SWITCH_FILE . " created"); | ||
} else { | ||
echo OutputText::error("Creating " . self::$SWITCH_FILE . ": " . self::getLastErrorMessage()); | ||
} | ||
} else { | ||
echo OutputText::info("The file " . self::$SWITCH_FILE . " already exists: no action taken."); | ||
} | ||
} | ||
|
||
public static function disable() | ||
{ | ||
if (file_exists(self::$SWITCH_FILE_PATH)) { | ||
// delete the file | ||
if (unlink(self::$SWITCH_FILE_PATH)) { | ||
echo OutputText::success(self::$SWITCH_FILE . " deleted"); | ||
} else { | ||
echo OutputText::error("Deleting " . self::$SWITCH_FILE . ": " . self::getLastErrorMessage()); | ||
} | ||
} else { | ||
echo OutputText::info("The file " . self::$SWITCH_FILE . " didn't exist: no action taken."); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<?php | ||
|
||
namespace Ushahidi\App\PlatformVerifier; | ||
|
||
use Ushahidi\App\Tools\OutputText; | ||
use Composer\Script\Event; | ||
use Composer\Installer\PackageEvent; | ||
|
||
class Env | ||
{ | ||
private static $NO_ENV = "Required environment variables missing and no environment file found."; | ||
private static $NO_ENV_EXPLAINER = "Please copy the '.env.example' file into a file named '.env' and set your missing variables."; | ||
private static $REQUIRED_ENV_KEYS = [ | ||
"DB_CONNECTION" => "Please set `DB_CONNECTION=mysql` in the environment or .env file.", | ||
"DB_HOST" => "Please set the address of your database in the DB_HOST key", | ||
"DB_PORT" => "Please set the port of your database in the DB_PORT key", | ||
"DB_DATABASE" => "Please set the name of your database in the DB_DATABASE key", | ||
"DB_USERNAME" => "Please set the username to connect to your database in the DB_USERNAME key", | ||
"DB_PASSWORD" => "Please set the password to connect to your database in the DB_PASSWORD key", | ||
"CACHE_DRIVER" => "Please set the CACHE_DRIVER according to your environment." . | ||
"See https://laravel.com/docs/5.8/cache#driver-prerequisites for more information on cache drivers.", | ||
"QUEUE_DRIVER" => "Please set the QUEUE_DRIVER according to your environment." . | ||
"See https://laravel.com/docs/5.8/queues for more information on queue drivers.", | ||
]; | ||
|
||
public function envExists() | ||
{ | ||
return file_exists(__DIR__ . "/../../.env"); | ||
} | ||
|
||
public function isMissingEnvKey($key) | ||
{ | ||
return !getenv($key); | ||
} | ||
public function verifyRequirements($console = true) | ||
{ | ||
$ok = "Good job! you have configured your system environment and/or .env file with all the required keys."; | ||
$info = "We will check the database connectivity next."; | ||
$errors = []; | ||
$success = []; | ||
|
||
if ($this->envExists()) { | ||
// load DotEnv for this script | ||
(new \Dotenv\Dotenv(__DIR__."/../../"))->load(); | ||
} | ||
|
||
$failures = false; | ||
foreach (self::$REQUIRED_ENV_KEYS as $key => $value) { | ||
if ($this->isMissingEnvKey($key)) { | ||
$failures = true; | ||
$message = [ | ||
"message" => "$key is missing in the environment or .env file.", | ||
"explainer" => $value | ||
]; | ||
array_push($errors, $message); | ||
} | ||
} | ||
// If there have been errors and the .env file is missing, point out that creating it | ||
// is a convenient way of solving those errors | ||
if (!empty($errors) && !$this->envExists()) { | ||
array_push($errors, ["message" => self::$NO_ENV, "explainer" => self::$NO_ENV_EXPLAINER], $console); | ||
} | ||
return $failures ? Respond::errorResponse($errors, $console) : Respond::successResponse($ok, $info, $console); | ||
} | ||
} |
Oops, something went wrong.