diff --git a/app/Http/Controllers/API/MigrationController.php b/app/Http/Controllers/API/MigrationController.php index 7aa7c0bbfe..1b0ddbe895 100644 --- a/app/Http/Controllers/API/MigrationController.php +++ b/app/Http/Controllers/API/MigrationController.php @@ -38,8 +38,8 @@ public function index(Request $request, $command = 'status') $command = 'status'; } - $db = service('db.config'); - $phinx_config = ['configuration' => realpath(APPPATH . '../phinx.php'), + $phinx_config = [ + 'configuration' => base_path('phinx.php'), 'parser' => 'php', ]; diff --git a/app/Http/Controllers/MigrateController.php b/app/Http/Controllers/MigrateController.php index e80ef1cdd2..9ead84208a 100644 --- a/app/Http/Controllers/MigrateController.php +++ b/app/Http/Controllers/MigrateController.php @@ -20,9 +20,8 @@ class MigrateController extends Controller public function migrate() { - $db = service('db.config'); $phinx_config = [ - 'configuration' => realpath(APPPATH . '../phinx.php'), + 'configuration' => base_path('phinx.php'), 'parser' => 'php', ]; diff --git a/app/Http/Controllers/RESTController.php b/app/Http/Controllers/RESTController.php index 5180800395..071d51d18b 100644 --- a/app/Http/Controllers/RESTController.php +++ b/app/Http/Controllers/RESTController.php @@ -202,6 +202,8 @@ protected function getRouteParams(Request $request) /** * Execute the usecase that the controller prepared. * + * @todo should this take Usecase as a param rather than use $this->usecase? + * * @throws HTTP_Exception_400 * @throws HTTP_Exception_403 * @throws HTTP_Exception_404 @@ -243,9 +245,6 @@ protected function executeUsecase(Request $request) */ protected function prepResponse(array $responsePayload = null, Request $request) { - // Add CORS headers to the response - // $this->add_cors_headers($this->response); - // Use JSON if the request method is OPTIONS if ($request->method() === Request::METHOD_OPTIONS) { $type = 'json'; @@ -255,45 +254,31 @@ protected function prepResponse(array $responsePayload = null, Request $request) $type = strtolower($request->query('format')) ?: 'json'; } - try { - //$format = service("formatter.output.$type"); - - // $body = $format($this->_response_payload); - // $mime = $format->getMimeType(); - // $this->response->headers('Content-Type', $mime); - - if (empty($responsePayload)) { - // If the payload is empty, return a 204 - // https://tools.ietf.org/html/rfc7231#section-6.3.5 - $response = response('', 204); - } else { - $response = response()->json( - $responsePayload, - 200, - [], - env('APP_DEBUG', false) ? JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES : null - ); - - if ($type === 'jsonp') { - $response->withCallback($request->input('callback')); - // Prevent Opera and Chrome from executing the response as anything - // other than JSONP, see T455. - $response->headers->set('X-Content-Type-Options', 'nosniff'); - } - } - - // Should we prevent this request from being cached? - if (! in_array($request->method(), $this->cacheableMethods)) { - $response->headers->set('Cache-Control', 'no-cache, no-store, max-age=0, must-revalidate'); + if (empty($responsePayload)) { + // If the payload is empty, return a 204 + // https://tools.ietf.org/html/rfc7231#section-6.3.5 + $response = response('', 204); + } else { + $response = response()->json( + $responsePayload, + 200, + [], + env('APP_DEBUG', false) ? JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES : null + ); + + if ($type === 'jsonp') { + $response->withCallback($request->input('callback')); + // Prevent Opera and Chrome from executing the response as anything + // other than JSONP + $response->headers->set('X-Content-Type-Options', 'nosniff'); } + } - return $response; - } catch (\Aura\Di\Exception\ServiceNotFound $e) { - abort(400, 'Unknown response format:' . $type); - } catch (\InvalidArgumentException $e) { - abort(400, 'Bad formatting parameters:' . $e->getMessage()); - } catch (\Ushahidi\Core\Exception\FormatterException $e) { - abort(500, 'Error while formatting response:' . $e->getMessage()); + // Should we prevent this request from being cached? + if (! in_array($request->method(), $this->cacheableMethods)) { + $response->headers->set('Cache-Control', 'no-cache, no-store, max-age=0, must-revalidate'); } + + return $response; } } diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index c9dd0ec6f8..2d4914e8a3 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -12,6 +12,26 @@ class AppServiceProvider extends ServiceProvider * @return void */ public function register() + { + $this->app->configure('cdn'); + $this->app->configure('media'); + $this->app->configure('ratelimiter'); + $this->app->configure('multisite'); + $this->app->configure('ohanzee-db'); + + $this->registerServicesFromAura(); + + $this->registerFilesystem(); + $this->registerMailer(); + $this->registerDataSources(); + + $this->configureAuraDI(); + + // Hack, must construct it to register route :/ + $this->app->make('datasources'); + } + + public function registerServicesFromAura() { $this->app->singleton(\Ushahidi\Factory\UsecaseFactory::class, function ($app) { // Just return it from AuraDI @@ -22,20 +42,10 @@ public function register() // Just return it from AuraDI return service('repository.message'); }); + } - $this->app->configure('cdn'); - $this->app->configure('ratelimiter'); - $this->app->configure('multisite'); - - // Add filesystem - $this->app->singleton('filesystem', function ($app) { - return $app->loadComponent( - 'filesystems', - \Illuminate\Filesystem\FilesystemServiceProvider::class, - 'filesystem' - ); - }); - + public function registerMailer() + { // Add mailer $this->app->singleton('mailer', function ($app) { return $app->loadComponent( @@ -44,8 +54,22 @@ public function register() 'mailer' ); }); + } + public function registerFilesystem() + { + // Add filesystem + $this->app->singleton('filesystem', function ($app) { + return $app->loadComponent( + 'filesystems', + \Illuminate\Filesystem\FilesystemServiceProvider::class, + 'filesystem' + ); + }); + } + public function registerDataSources() + { $this->app->singleton('datasources', function () { return $this->app->loadComponent( 'datasources', @@ -53,94 +77,45 @@ public function register() 'datasources' ); }); - - $this->configureAuraDI(); - - // Hack, must construct it to register route :/ - $this->app->make('datasources'); } - // @todo move most of this elsewhere protected function configureAuraDI() { $di = service(); - // Multisite db - $di->set('site', function () use ($di) { - $site = ''; - - // Is this a multisite install? - $multisite = config('multisite.enabled'); - if ($multisite) { - $site = $di->get('multisite')->getSite(); - } - - return $site; - }); - - // Site config - $di->set('site.config', function () use ($di) { - return $di->get('repository.config')->get('site')->asArray(); - }); - - // Client Url - $di->set('clienturl', function () use ($di) { - return $this->getClientUrl($di->get('site.config')); - }); - - // Feature config - $di->set('features', function () use ($di) { - return $di->get('repository.config')->get('features')->asArray(); - }); - - // Roles config settings - $di->set('roles.enabled', function () use ($di) { - $config = $di->get('features'); - - return $config['roles']['enabled']; - }); - - // Feature config - $di->set('features.limits', function () use ($di) { - $config = $di->get('features'); - - return $config['limits']; - }); - - // Webhooks config settings - $di->set('webhooks.enabled', function () use ($di) { - $config = $di->get('features'); - - return $config['webhooks']['enabled']; - }); - - // Post Locking config settings - $di->set('post-locking.enabled', function () use ($di) { - $config = $di->get('features'); - - return $config['post-locking']['enabled']; - }); + $this->configureAuraServices($di); + $this->injectAuraConfig($di); + } - // Redis config settings - $di->set('redis.enabled', function () use ($di) { - $config = $di->get('features'); + protected function configureAuraServices(\Aura\Di\ContainerInterface $di) + { + // Configure mailer + $di->set('tool.mailer', $di->lazyNew('Ushahidi\App\Tools\LumenMailer', [ + 'mailer' => app('mailer'), + 'siteConfig' => $di->lazyGet('site.config'), + 'clientUrl' => $di->lazyGet('clienturl') + ])); - return $config['redis']['enabled']; - }); + // Setup user session service + $di->set('session', $di->lazyNew(\Ushahidi\App\Tools\LumenSession::class, [ + 'userRepo' => $di->lazyGet('repository.user') + ])); - // Data import config settings - $di->set('data-import.enabled', function () use ($di) { - $config = $di->get('features'); + // Multisite db + $di->set('kohana.db.multisite', function () use ($di) { + $config = config('ohanzee-db'); - return $config['data-import']['enabled']; + return \Ohanzee\Database::instance('multisite', $config['default']); }); - $di->set('features.data-providers', function () use ($di) { - $config = $di->get('features'); - - return array_filter($config['data-providers']); + // Deployment db + $di->set('kohana.db', function () use ($di) { + return \Ohanzee\Database::instance('deployment', $this->getDbConfig($di)); }); + } + protected function injectAuraConfig(\Aura\Di\ContainerInterface $di) + { // CDN Config settings $di->set('cdn.config', function () use ($di) { return config('cdn'); @@ -151,15 +126,22 @@ protected function configureAuraDI() return config('ratelimiter'); }); - // Private deployment config settings - // @todo move to repo - $di->set('site.private', function () use ($di) { - $site = $di->get('site.config'); - $features = $di->get('features'); - return $site['private'] - and $features['private']['enabled']; + // Multisite db + // Move multisite enabled check to class and move to src/App + $di->set('site', function () use ($di) { + // @todo default to using the current domain + $site = ''; + + // Is this a multisite install? + $multisite = config('multisite.enabled'); + if ($multisite) { + $site = $di->get('multisite')->getSite(); + } + + return $site; }); + // Move multisite enabled check to class and move to src/App $di->set('tool.uploader.prefix', function () use ($di) { // Is this a multisite install? $multisite = config('multisite.enabled'); @@ -170,17 +152,26 @@ protected function configureAuraDI() return ''; }); - // Configure mailer - $di->set('tool.mailer', $di->lazyNew('Ushahidi\App\Tools\LumenMailer', [ - 'mailer' => app('mailer'), - 'siteConfig' => $di->lazyGet('site.config'), - 'clientUrl' => $di->lazyGet('clienturl') - ])); + // Client Url + $di->set('clienturl', function () use ($di) { + return $this->getClientUrl($di->get('site.config')); + }); + } - // @todo move to auth provider? - $di->set('session', $di->lazyNew(\Ushahidi\App\Tools\LumenSession::class, [ - 'userRepo' => $di->lazyGet('repository.user') - ])); + protected function getDbConfig(\Aura\Di\ContainerInterface $di) + { + // Kohana injection + // DB config + $config = config('ohanzee-db'); + $config = $config['default']; + + // Is this a multisite install? + $multisite = config('multisite.enabled'); + if ($multisite) { + $config = $di->get('multisite')->getDbConfig(); + } + + return $config; } protected function getClientUrl($config) diff --git a/application/bootstrap.php b/application/bootstrap.php deleted file mode 100755 index 77f39144d9..0000000000 --- a/application/bootstrap.php +++ /dev/null @@ -1,153 +0,0 @@ - - * @package Ushahidi\Application - * @copyright 2013 Ushahidi - * @license https://www.gnu.org/licenses/agpl-3.0.html GNU Affero General Public License Version 3 (AGPL3) - */ - -// -- Environment setup -------------------------------------------------------- - -/** - * Load the core Kohana class - */ -require SYSPATH.'classes/Kohana/Core'.EXT; - -if (is_file(APPPATH.'classes/Kohana'.EXT)) -{ - // Application extends the core - require APPPATH.'classes/Kohana'.EXT; -} -else -{ - // Load empty core extension - require SYSPATH.'classes/Kohana'.EXT; -} - -/** - * Set the default time zone. - * - * @link http://kohanaframework.org/guide/using.configuration - * @link http://www.php.net/manual/timezones - */ -date_default_timezone_set('UTC'); - -/** - * Set the default locale. - * - * @link http://kohanaframework.org/guide/using.configuration - * @link http://www.php.net/manual/function.setlocale - */ -setlocale(LC_ALL, 'en_US.utf-8'); - -/** - * Enable the Kohana auto-loader. - * - * @link http://kohanaframework.org/guide/using.autoloading - * @link http://www.php.net/manual/function.spl-autoload-register - */ -spl_autoload_register(array('Kohana', 'auto_load')); - -/** - * Enable the Kohana auto-loader for unserialization. - * - * @link http://www.php.net/manual/function.spl-autoload-call - * @link http://www.php.net/manual/var.configuration#unserialize-callback-func - */ -ini_set('unserialize_callback_func', 'spl_autoload_call'); - -// -- Configuration and initialization ----------------------------------------- - -/** - * Set the default language - */ -I18n::lang('en-us'); - -/** - * Add response message for HTTP 422 - */ -Kohana_Response::$messages[422] = 'Unprocessable Entity'; - -/** - * Set Kohana::$environment if a 'KOHANA_ENV' environment variable has been supplied. - * - * Note: If you supply an invalid environment name 'development' will be used instead - */ -if (($env = getenv('KOHANA_ENV')) === FALSE OR defined('Kohana::'.strtoupper($env)) === FALSE) -{ - $env = 'development'; -} - -// Ignoring code standards error about constant case -// @codingStandardsIgnoreStart -Kohana::$environment = constant('Kohana::'.strtoupper($env)); -// @codingStandardsIgnoreEnd - -/** - * Attach a file reader to config. Multiple readers are supported. - */ - -Kohana::$config = new Config; -Kohana::$config->attach(new Config_File); - -/** - * Attach the environment specific configuration file reader to config - */ -Kohana::$config->attach(new Config_File('config/environments/'.$env)); - -/** - * Initialize Kohana, setting the default options. - */ -Kohana::init(Kohana::$config->load('init')->as_array()); - -/** - * Attach the file write to logging. Multiple writers are supported. - */ -Kohana::$log->attach(new Log_File(APPPATH.'logs')); - -/** - * Enable modules. Modules are referenced by a relative or absolute path. - */ -Kohana::modules(Kohana::$config->load('modules')->as_array()); - -/** - * Set cookie salt - * @TODO change this for your project - */ -Cookie::$salt = 'ushahidi-insecure-please-change-me'; - -/** - * If the RAVEN_URL is defined, set up raven error logging - */ -if (getenv("RAVEN_URL")) -{ - $client = new Raven_Client(getenv("RAVEN_URL")); - - $error_handler = new Raven_ErrorHandler($client); - $error_handler->registerExceptionHandler(); - $error_handler->registerErrorHandler(); - $error_handler->registerShutdownFunction(); - - Kohana::$log->attach(new Log_Raven($client)); -} - -/** - * Initialize Ushahidi, setting the defaults - * Note: We have to do this before routing kicks in, so that the 'default' route doesn't catch any custom plugin routes. - */ -Ushahidi::init(); - -/** - * Include default routes. Default routes are located in application/routes/default.php - */ -include Kohana::find_file('routes', 'default'); - -/** - * Include the routes for the current environment. - */ -if ($routes = Kohana::find_file('routes', Kohana::$environment)) -{ - include $routes; -} diff --git a/application/cache/.gitignore b/application/cache/.gitignore deleted file mode 100644 index 50b9fa4bce..0000000000 --- a/application/cache/.gitignore +++ /dev/null @@ -1,5 +0,0 @@ -# Ignore all files -* -# Except this file -!.gitignore -# To prevent cache files from ever being committed into the git repo. diff --git a/application/classes/Database/MySQLi.php b/application/classes/Database/MySQLi.php deleted file mode 100644 index 186482a4b2..0000000000 --- a/application/classes/Database/MySQLi.php +++ /dev/null @@ -1,406 +0,0 @@ -_connection) - return; - - if (Database_MySQLi::$_set_names === NULL) - { - // Determine if we can use mysqli_set_charset(), which is only - // available on PHP 5.2.3+ when compiled against MySQL 5.0+ - Database_MySQLi::$_set_names = ! function_exists('mysqli_set_charset'); - } - - // Extract the connection parameters, adding required variabels - extract($this->_config['connection'] + array( - 'database' => '', - 'hostname' => '', - 'username' => '', - 'password' => '', - 'socket' => '', - 'port' => 3306, - )); - - // Prevent this information from showing up in traces - unset($this->_config['connection']['username'], $this->_config['connection']['password']); - - try - { - $this->_connection = new mysqli($hostname, $username, $password, $database, $port, $socket); - } - catch (Exception $e) - { - // No connection exists - $this->_connection = NULL; - - throw new Database_Exception(':error', array(':error' => $e->getMessage()), $e->getCode()); - } - - // \xFF is a better delimiter, but the PHP driver uses underscore - $this->_connection_id = sha1($hostname.'_'.$username.'_'.$password); - - if ( ! empty($this->_config['charset'])) - { - // Set the character set - $this->set_charset($this->_config['charset']); - } - - if ( ! empty($this->_config['connection']['variables'])) - { - // Set session variables - $variables = array(); - - foreach ($this->_config['connection']['variables'] as $var => $val) - { - $variables[] = 'SESSION '.$var.' = '.$this->quote($val); - } - - $this->_connection->query('SET '.implode(', ', $variables)); - } - } - - public function disconnect() - { - try - { - // Database is assumed disconnected - $status = TRUE; - - if (is_resource($this->_connection)) - { - if ($status = $this->_connection->close()) - { - // Clear the connection - $this->_connection = NULL; - - // Clear the instance - parent::disconnect(); - } - } - } - catch (Exception $e) - { - // Database is probably not disconnected - $status = ! is_resource($this->_connection); - } - - return $status; - } - - public function set_charset($charset) - { - // Make sure the database is connected - $this->_connection or $this->connect(); - - if (Database_MySQLi::$_set_names === TRUE) - { - // PHP is compiled against MySQL 4.x - $status = (bool) $this->_connection->query('SET NAMES '.$this->quote($charset)); - } - else - { - // PHP is compiled against MySQL 5.x - $status = $this->_connection->set_charset($charset); - } - - if ($status === FALSE) - { - throw new Database_Exception(':error', array(':error' => $this->_connection->error), $this->_connection->errno); - } - } - - public function query($type, $sql, $as_object = FALSE, array $params = NULL) - { - // Make sure the database is connected - $this->_connection or $this->connect(); - - if (Kohana::$profiling) - { - // Benchmark this query for the current instance - $benchmark = Profiler::start("Database ({$this->_instance})", $sql); - } - - // Execute the query - if (($result = $this->_connection->query($sql)) === FALSE) - { - if (isset($benchmark)) - { - // This benchmark is worthless - Profiler::delete($benchmark); - } - - throw new Database_Exception(':error [ :query ]', array( - ':error' => $this->_connection->error, - ':query' => $sql - ), $this->_connection->errno); - } - - if (isset($benchmark)) - { - Profiler::stop($benchmark); - } - - // Set the last query - $this->last_query = $sql; - - if ($type === Database::SELECT) - { - // Return an iterator of results - return new Database_MySQLi_Result($result, $sql, $as_object, $params); - } - elseif ($type === Database::INSERT) - { - // Return a list of insert id and rows created - return array( - $this->_connection->insert_id, - $this->_connection->affected_rows, - ); - } - else - { - // Return the number of rows affected - return $this->_connection->affected_rows; - } - } - - public function datatype($type) - { - static $types = array - ( - 'blob' => array('type' => 'string', 'binary' => TRUE, 'character_maximum_length' => '65535'), - 'bool' => array('type' => 'bool'), - 'bigint unsigned' => array('type' => 'int', 'min' => '0', 'max' => '18446744073709551615'), - 'datetime' => array('type' => 'string'), - 'decimal unsigned' => array('type' => 'float', 'exact' => TRUE, 'min' => '0'), - 'double' => array('type' => 'float'), - 'double precision unsigned' => array('type' => 'float', 'min' => '0'), - 'double unsigned' => array('type' => 'float', 'min' => '0'), - 'enum' => array('type' => 'string'), - 'fixed' => array('type' => 'float', 'exact' => TRUE), - 'fixed unsigned' => array('type' => 'float', 'exact' => TRUE, 'min' => '0'), - 'float unsigned' => array('type' => 'float', 'min' => '0'), - 'geometry' => array('type' => 'string', 'binary' => TRUE), - 'int unsigned' => array('type' => 'int', 'min' => '0', 'max' => '4294967295'), - 'integer unsigned' => array('type' => 'int', 'min' => '0', 'max' => '4294967295'), - 'longblob' => array('type' => 'string', 'binary' => TRUE, 'character_maximum_length' => '4294967295'), - 'longtext' => array('type' => 'string', 'character_maximum_length' => '4294967295'), - 'mediumblob' => array('type' => 'string', 'binary' => TRUE, 'character_maximum_length' => '16777215'), - 'mediumint' => array('type' => 'int', 'min' => '-8388608', 'max' => '8388607'), - 'mediumint unsigned' => array('type' => 'int', 'min' => '0', 'max' => '16777215'), - 'mediumtext' => array('type' => 'string', 'character_maximum_length' => '16777215'), - 'national varchar' => array('type' => 'string'), - 'numeric unsigned' => array('type' => 'float', 'exact' => TRUE, 'min' => '0'), - 'nvarchar' => array('type' => 'string'), - 'point' => array('type' => 'string', 'binary' => TRUE), - 'real unsigned' => array('type' => 'float', 'min' => '0'), - 'set' => array('type' => 'string'), - 'smallint unsigned' => array('type' => 'int', 'min' => '0', 'max' => '65535'), - 'text' => array('type' => 'string', 'character_maximum_length' => '65535'), - 'tinyblob' => array('type' => 'string', 'binary' => TRUE, 'character_maximum_length' => '255'), - 'tinyint' => array('type' => 'int', 'min' => '-128', 'max' => '127'), - 'tinyint unsigned' => array('type' => 'int', 'min' => '0', 'max' => '255'), - 'tinytext' => array('type' => 'string', 'character_maximum_length' => '255'), - 'year' => array('type' => 'string'), - ); - - $type = str_replace(' zerofill', '', $type); - - if (isset($types[$type])) - return $types[$type]; - - return parent::datatype($type); - } - - /** - * Start a SQL transaction - * - * @link http://dev.mysql.com/doc/refman/5.0/en/set-transaction.html - * - * @param string $mode Isolation level - * @return boolean - */ - public function begin($mode = NULL) - { - // Make sure the database is connected - $this->_connection or $this->connect(); - - if ($mode AND ! $this->_connection->query("SET TRANSACTION ISOLATION LEVEL $mode")) - { - throw new Database_Exception(':error', array( - ':error' => $this->_connection->error - ), $this->_connection->errno); - } - - return (bool) $this->_connection->query('START TRANSACTION'); - } - - /** - * Commit a SQL transaction - * - * @return boolean - */ - public function commit() - { - // Make sure the database is connected - $this->_connection or $this->connect(); - - return (bool) $this->_connection->query('COMMIT'); - } - - /** - * Rollback a SQL transaction - * - * @return boolean - */ - public function rollback() - { - // Make sure the database is connected - $this->_connection or $this->connect(); - - return (bool) $this->_connection->query('ROLLBACK'); - } - - public function list_tables($like = NULL) - { - if (is_string($like)) - { - // Search for table names - $result = $this->query(Database::SELECT, 'SHOW TABLES LIKE '.$this->quote($like), FALSE); - } - else - { - // Find all table names - $result = $this->query(Database::SELECT, 'SHOW TABLES', FALSE); - } - - $tables = array(); - foreach ($result as $row) - { - $tables[] = reset($row); - } - - return $tables; - } - - public function list_columns($table, $like = NULL, $add_prefix = TRUE) - { - // Quote the table name - $table = ($add_prefix === TRUE) ? $this->quote_table($table) : $table; - - if (is_string($like)) - { - // Search for column names - $result = $this->query(Database::SELECT, 'SHOW FULL COLUMNS FROM '.$table.' LIKE '.$this->quote($like), FALSE); - } - else - { - // Find all column names - $result = $this->query(Database::SELECT, 'SHOW FULL COLUMNS FROM '.$table, FALSE); - } - - $count = 0; - $columns = array(); - foreach ($result as $row) - { - list($type, $length) = $this->_parse_type($row['Type']); - - $column = $this->datatype($type); - - $column['column_name'] = $row['Field']; - $column['column_default'] = $row['Default']; - $column['data_type'] = $type; - $column['is_nullable'] = ($row['Null'] == 'YES'); - $column['ordinal_position'] = ++$count; - - switch ($column['type']) - { - case 'float': - if (isset($length)) - { - list($column['numeric_precision'], $column['numeric_scale']) = explode(',', $length); - } - break; - case 'int': - if (isset($length)) - { - // MySQL attribute - $column['display'] = $length; - } - break; - case 'string': - switch ($column['data_type']) - { - case 'binary': - case 'varbinary': - $column['character_maximum_length'] = $length; - break; - case 'char': - case 'varchar': - $column['character_maximum_length'] = $length; - case 'text': - case 'tinytext': - case 'mediumtext': - case 'longtext': - $column['collation_name'] = $row['Collation']; - break; - case 'enum': - case 'set': - $column['collation_name'] = $row['Collation']; - $column['options'] = explode('\',\'', substr($length, 1, -1)); - break; - } - break; - } - - // MySQL attributes - $column['comment'] = $row['Comment']; - $column['extra'] = $row['Extra']; - $column['key'] = $row['Key']; - $column['privileges'] = $row['Privileges']; - - $columns[$row['Field']] = $column; - } - - return $columns; - } - - public function escape($value) - { - // Make sure the database is connected - $this->_connection or $this->connect(); - - if (($value = $this->_connection->real_escape_string( (string) $value)) === FALSE) - { - throw new Database_Exception(':error', array( - ':error' => $this->_connection->error, - ), $this->_connection->errno); - } - - // SQL standard is to use single-quotes for all values - return "'$value'"; - } - -} // End Database_MySQLi diff --git a/application/classes/Database/MySQLi/Result.php b/application/classes/Database/MySQLi/Result.php deleted file mode 100644 index 7d6054625d..0000000000 --- a/application/classes/Database/MySQLi/Result.php +++ /dev/null @@ -1,71 +0,0 @@ -_total_rows = $result->num_rows; - } - - public function __destruct() - { - if (is_resource($this->_result)) - { - $this->_result->free(); - } - } - - public function seek($offset) - { - if ($this->offsetExists($offset) AND $this->_result->data_seek($offset)) - { - // Set the current row to the offset - $this->_current_row = $this->_internal_row = $offset; - - return TRUE; - } - else - { - return FALSE; - } - } - - public function current() - { - if ($this->_current_row !== $this->_internal_row AND ! $this->seek($this->_current_row)) - return NULL; - - // Increment internal row for optimization assuming rows are fetched in order - $this->_internal_row++; - - if ($this->_as_object === TRUE) - { - // Return an stdClass - return $this->_result->fetch_object(); - } - elseif (is_string($this->_as_object)) - { - // Return an object of given class name - return $this->_result->fetch_object($this->_as_object, (array) $this->_object_params); - } - else - { - // Return an array of the row - return $this->_result->fetch_assoc(); - } - } - -} // End Database_MySQLi_Result_Select \ No newline at end of file diff --git a/application/classes/Exception/Login.php b/application/classes/Exception/Login.php deleted file mode 100644 index 55f4e125b8..0000000000 --- a/application/classes/Exception/Login.php +++ /dev/null @@ -1,12 +0,0 @@ - - * @package Ushahidi\Exception - * @copyright 2013 Ushahidi - * @license https://www.gnu.org/licenses/agpl-3.0.html GNU Affero General Public License Version 3 (AGPL3) - */ - -class Exception_Login extends HTTP_Exception_401 { -} \ No newline at end of file diff --git a/application/classes/HTTP/Exception.php b/application/classes/HTTP/Exception.php deleted file mode 100644 index 4c319f5e5d..0000000000 --- a/application/classes/HTTP/Exception.php +++ /dev/null @@ -1,28 +0,0 @@ - - * @package Ushahidi\Exception - * @copyright 2013 Ushahidi - * @license https://www.gnu.org/licenses/agpl-3.0.html GNU Affero General Public License Version 3 (AGPL3) - */ - -class HTTP_Exception extends Kohana_HTTP_Exception { - use Ushahidi_Corsheaders; - - /** - * Generate a Response for the current Exception - * - * @uses Kohana_Exception::response() - * @return Response - */ - public function get_response() - { - $response = parent::get_response(); - $this->add_cors_headers($response); - - return $response; - } - -} diff --git a/application/classes/HTTP/Exception/422.php b/application/classes/HTTP/Exception/422.php deleted file mode 100644 index e17c03eabf..0000000000 --- a/application/classes/HTTP/Exception/422.php +++ /dev/null @@ -1,45 +0,0 @@ - $user)); - * - * @param string $message status message, custom content to display with error - * @param array $variables translation variables - * @return void - */ - public function __construct($message = NULL, array $variables = NULL, Exception $previous = NULL, Array $errors = NULL) - { - if ($errors) { - $this->setErrors($errors); - } - - if (method_exists($previous, 'getErrors')) { - $this->setErrors($previous->getErrors()); - } - - parent::__construct($message, $variables, $previous); - } - - public function setErrors(Array $errors) - { - $this->errors = $errors; - } - - public function getErrors() - { - return $this->errors ?: array(); - } - -} diff --git a/application/classes/HTTP/Exception/Expected.php b/application/classes/HTTP/Exception/Expected.php deleted file mode 100644 index 9713ec6b65..0000000000 --- a/application/classes/HTTP/Exception/Expected.php +++ /dev/null @@ -1,25 +0,0 @@ -check(); - - // Use Kohana_Exception to get a response with a response body - $response = Kohana_Exception::response($this); - // Copy headers from $this->_response - $response->headers((array)$this->_response->headers()); - // Add CORS Headers - $this->add_cors_headers($response); - - return $response; - } - -} diff --git a/application/classes/Kohana/Exception.php b/application/classes/Kohana/Exception.php deleted file mode 100644 index 028e104b70..0000000000 --- a/application/classes/Kohana/Exception.php +++ /dev/null @@ -1,32 +0,0 @@ - - * @package Ushahidi\Exception - * @copyright 2013 Ushahidi - * @license https://www.gnu.org/licenses/agpl-3.0.html GNU Affero General Public License Version 3 (AGPL3) - */ - -class Kohana_Exception extends Kohana_Kohana_Exception { - use Ushahidi_Corsheaders; - - /** - * @var string error rendering view - */ - public static $error_view = 'error/api'; - - /** - * @var string error view content type - */ - public static $error_view_content_type = 'application/json'; - - public static function response(Exception $e) - { - $response = parent::response($e); - self::static_add_cors_headers($response); - - return $response; - } - -} diff --git a/application/classes/Log/Raven.php b/application/classes/Log/Raven.php deleted file mode 100644 index 07dcb44196..0000000000 --- a/application/classes/Log/Raven.php +++ /dev/null @@ -1,75 +0,0 @@ - Raven_Client::FATAL, - Kohana_Log::ALERT => Raven_Client::FATAL, - Kohana_Log::CRITICAL => Raven_Client::FATAL, - Kohana_Log::ERROR => Raven_Client::ERROR, - Kohana_Log::WARNING => Raven_Client::WARNING, - Kohana_Log::NOTICE => Raven_Client::INFO, - Kohana_Log::INFO => Raven_Client::INFO, - Kohana_Log::DEBUG => Raven_Client::DEBUG, - 8 => Raven_Client::DEBUG, - ]; - - /** - * Creates a new raven logger. - * - * $writer = new Raven_Log(); - * - * @param string log directory - * @return void - */ - public function __construct($client) - { - $this->raven = $client; - } - - /** - * Writes each of the messages into the raven. - * - * $writer->write($messages); - * - * @param array messages - * @return void - */ - public function write(array $messages) - { - foreach ($messages as $message) - { - if (isset($message['additional']['exception'])) - { - // Write each message into the log file - // Format: time --- level: body - $this->raven->captureException($message['additional']['exception']); - } else { - // Write each message into the log file - // Format: time --- level: body - $this->raven->captureMessage( - $this->format_message($message), - $message, - [ - 'level' => $this->mapRavenLevel($message['level']) - ], - $message['trace'] - ); - } - } - } - - private function mapRavenLevel($level) { - return isset(self::$errorLevelMap[$level]) ? self::$errorLevelMap[$level] : Raven_Client::INFO; - } -} diff --git a/application/classes/Log/Writer.php b/application/classes/Log/Writer.php deleted file mode 100644 index 482a36cca2..0000000000 --- a/application/classes/Log/Writer.php +++ /dev/null @@ -1,35 +0,0 @@ - - * @package Ushahidi\Log - * @copyright 2013 Ushahidi - * @license https://www.gnu.org/licenses/agpl-3.0.html GNU Affero General Public License Version 3 (AGPL3) - */ - -abstract class Log_Writer extends Kohana_Log_Writer { - - /** - * Formats a log entry. - * - * Fixes PHP 5.4 compatibility issues - * - * @param array $message - * @param string $format - * @return string - */ - public function format_message(array $message, $format = "time site --- level: body in file:line") - { - try { - $dbconfig = service('db.config'); // hacky - use db name as fallback - $message['site'] = service('site') ?: $dbconfig['connection']['database']; - } catch (Exception $e) { - // Ignore errors, they're probably why we're here to start with - $message['site'] = ''; - } - - return parent::format_message(array_filter($message, 'is_scalar'), $format); - } - -} diff --git a/application/classes/Ushahidi.php b/application/classes/Ushahidi.php deleted file mode 100644 index 8c78b7f908..0000000000 --- a/application/classes/Ushahidi.php +++ /dev/null @@ -1,2 +0,0 @@ - - * @package Ushahidi\Application - * @copyright 2014 Ushahidi - * @license https://www.gnu.org/licenses/agpl-3.0.html GNU Affero General Public License Version 3 (AGPL3) - */ - -class Ushahidi_Config extends Ushahidi_Config_Database {} diff --git a/application/classes/Ushahidi/Config/Database.php b/application/classes/Ushahidi/Config/Database.php deleted file mode 100644 index 1d13c78208..0000000000 --- a/application/classes/Ushahidi/Config/Database.php +++ /dev/null @@ -1,82 +0,0 @@ - - * @package Ushahidi\Application - * @copyright 2014 Ushahidi - * @license https://www.gnu.org/licenses/agpl-3.0.html GNU Affero General Public License Version 3 (AGPL3) - */ -class Ushahidi_Config_Database extends Config_Database -{ - - protected static $groups; - - /** - * Get allowed groups - * @return array - */ - public static function groups() - { - return static::$groups ?: array(); - } - - public function __construct(array $config = NULL) - { - parent::__construct($config); - - if (isset($config['groups'])) - { - static::$groups = $config['groups']; - } - } - - /** - * Tries to load the specificed configuration group - * - * Returns FALSE if group does not exist or an array if it does - * - * @param string $group Configuration group - * @return boolean|array - */ - public function load($group) - { - if (! in_array($group, static::groups())) - { - return FALSE; - } - - return parent::load($group); - } - - /** - * Encode a configuration value for storage. - * - * Uses json_encode() - * - * @param mixed $value raw config value - * @return string - */ - protected function _encode($value) - { - return json_encode($value); - } - - /** - * Decode a configuration value from storage. - * - * Uses json_decode() - * - * @param string $value encoded config value - * @return mixed - */ - protected function _decode($value) - { - return json_decode($value, true); - } - -} diff --git a/application/classes/Ushahidi/Core.php b/application/classes/Ushahidi/Core.php deleted file mode 100644 index bd83d41da8..0000000000 --- a/application/classes/Ushahidi/Core.php +++ /dev/null @@ -1,123 +0,0 @@ - - * @package Ushahidi\Application - * @copyright 2013 Ushahidi - * @license https://www.gnu.org/licenses/agpl-3.0.html GNU Affero General Public License Version 3 (AGPL3) - */ - -abstract class Ushahidi_Core { - - /** - * Initializes Ushahidi and Plugins - */ - public static function init() - { - /** - * 0. Register depenendencies for injection. - */ - $di = service(); - - // Kohana injection - // DB config - $di->set('db.config', function() use ($di) { - $config = Kohana::$config->load('database')->default; - - // Is this a multisite install? - $multisite = config('multisite.enabled'); - if ($multisite) { - $config = $di->get('multisite')->getDbConfig(); - } - - return $config; - }); - // Multisite db - $di->set('kohana.db.multisite', function () use ($di) { - return Ohanzee\Database::instance('multisite', Kohana::$config->load('database')->default); - }); - // Deployment db - $di->set('kohana.db', function() use ($di) { - return Ohanzee\Database::instance('deployment', $di->get('db.config')); - }); - - // Intercom config settings - $di->set('thirdparty.intercomAppToken', function() use ($di) { - return getenv('INTERCOM_APP_TOKEN'); - }); - - /** - * 1. Load the plugins - */ - self::load(); - - /** - * Attach database config - */ - // self::attached_db_config(); - } - - public static function attached_db_config() - { - // allowed groups are stored with the config service. - $groups = service('repository.config')->groups(); - - $db = service('kohana.db'); - - /** - * Attach database config to override some settings - */ - try - { - if (DB::query(Database::SELECT, 'SHOW TABLES LIKE \'config\'')->execute($db)->count() > 0) - { - Kohana::$config->attach(new Ushahidi_Config([ - 'groups' => $groups, - 'instance' => $db - ])); - } - } - catch (Exception $e) - { - // Ignore errors if database table doesn't exist yet - } - } - - /** - * Load All Plugins Into System - */ - public static function load() - { - if (! defined('PLUGINPATH') OR ! is_dir(PLUGINPATH)) return; - - // Load Plugins - $results = scandir(PLUGINPATH); - foreach ($results as $result) - { - if ($result === '.' or $result === '..') continue; - - if (is_dir(PLUGINPATH.$result)) - { - Kohana::modules( array($result => PLUGINPATH.$result) + Kohana::modules() ); - } - } - } - - /** - * Useful for development. Only intended for temporary debugging. - */ - public static function log(/* anything */) - { - $message = ''; - foreach (func_get_args() as $arg) { - $message .= (is_string($arg) ? $arg : var_export($arg, true)) . "\n"; - } - - $log = \Log::instance(); - $log->add(Log::INFO, $message); - } -} diff --git a/application/classes/Ushahidi/Corsheaders.php b/application/classes/Ushahidi/Corsheaders.php deleted file mode 100644 index 220d2ea3d8..0000000000 --- a/application/classes/Ushahidi/Corsheaders.php +++ /dev/null @@ -1,37 +0,0 @@ - - * @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) - */ - -trait Ushahidi_Corsheaders { - - protected function add_cors_headers(HTTP_Response &$response) - { - $response->headers('Access-Control-Allow-Origin', '*'); - $response->headers('Access-Control-Allow-Headers', 'Authorization, Content-type'); - - if (isset($this->_action_map)) - { - $allow_methods = implode(', ', array_keys($this->_action_map)); - $response->headers('Allow', $allow_methods); - $response->headers('Access-Control-Allow-Methods', $allow_methods); - } - - return $response; - } - - protected static function static_add_cors_headers(HTTP_Response &$response) - { - $response->headers('Access-Control-Allow-Origin', '*'); - $response->headers('Access-Control-Allow-Headers', 'Authorization, Content-type'); - - return $response; - } - -} diff --git a/application/classes/Ushahidi/Mailer.php b/application/classes/Ushahidi/Mailer.php deleted file mode 100644 index 9aacfb2f42..0000000000 --- a/application/classes/Ushahidi/Mailer.php +++ /dev/null @@ -1,66 +0,0 @@ - - * @package Ushahidi\Application - * @copyright 2014 Ushahidi - * @license https://www.gnu.org/licenses/agpl-3.0.html GNU Affero General Public License Version 3 (AGPL3) - */ - -use Ushahidi\Core\Tool\Mailer; -use Shadowhand\Email; -use League\Url\Url; - -class Ushahidi_Mailer implements Mailer -{ - public function __construct($siteConfig, $clientUrl) - { - $this->siteConfig = $siteConfig; - $this->clientUrl = $clientUrl; - } - - public function send($to, $type, Array $params = null) - { - $method = "send_".$type; - if (method_exists($this, $method)) { - $this->$method($to, $params); - } else { - // Exception - throw new Exception('Unsupported mail type: ' + $type); - } - } - - protected function send_resetpassword($to, $params) - { - $site_name = $this->siteConfig['name']; - $site_email = $this->siteConfig['email']; - $multisite_email = Kohana::$config->load('multisite.email'); - - // @todo make this more robust - if ($multisite_email) { - $from_email = $multisite_email; - } elseif ($site_email) { - $from_email = $site_email; - } else { - $url = Url::createFromServer($_SERVER); - $host = $url->getHost()->toUnicode(); - $from_email = 'noreply@' . $host; - } - - $view = View::factory('email/forgot-password'); - $view->site_name = $site_name; - $view->token = $params['token']; - $view->client_url = $this->clientUrl; - $message = $view->render(); - - $subject = $site_name . ': Password reset'; - - $email = Email::factory($subject, $message, 'text/html') - ->to($to) - ->from($from_email, $site_name) - ->send() - ; - } -} diff --git a/application/classes/Ushahidi/Rest.php b/application/classes/Ushahidi/Rest.php deleted file mode 100644 index 88054704ef..0000000000 --- a/application/classes/Ushahidi/Rest.php +++ /dev/null @@ -1,559 +0,0 @@ - - * @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) - */ - -use Ushahidi\Api\Endpoint; -use League\OAuth2\Server\Exception\OAuth2Exception; -use League\OAuth2\Server\Exception\MissingAccessTokenException; - -abstract class Ushahidi_Rest extends Controller { - use Ushahidi_Corsheaders; - - /** - * @var Current API version - */ - protected static $version = '3'; - - /** - * @var Object Request Payload - */ - protected $_request_payload = NULL; - - /** - * @var Object Response Payload - */ - protected $_response_payload = NULL; - - /** - * @var array Map of HTTP methods -> actions - */ - protected $_action_map = array - ( - Http_Request::POST => 'post', // Typically Create.. - Http_Request::GET => 'get', - Http_Request::PUT => 'put', // Typically Update.. - Http_Request::DELETE => 'delete', - Http_Request::OPTIONS => 'options' - ); - - /** - * @var array List of HTTP methods which support body content - */ - protected $_methods_with_body_content = array - ( - Http_Request::POST, - Http_Request::PUT, - ); - - /** - * @var array List of HTTP methods which may be cached - */ - protected $_cacheable_methods = array - ( - Http_Request::GET, - ); - - /** - * @var Usecase - */ - protected $_usecase; - - public function before() - { - parent::before(); - - $this->_parse_request(); - $this->_check_access(); - } - - // Controller - public function after() - { - $this->_prepare_response(); - - parent::after(); - } - - /** - * Get current api version - */ - public static function version() - { - return self::$version; - } - - /** - * Get an API URL for a resource. - * @param string $resource - * @param mixed $id - * @return string - */ - public static function url($resource, $id = null) - { - $template = 'api/v%d/%s'; - if (!is_null($id)) { - $template .= '/%s'; - } - return rtrim(sprintf($template, static::version(), $resource, $id), '/'); - } - - /** - * Get options for a resource collection. - * - * OPTIONS /api/foo - * - * @return void - */ - public function action_options_index_collection() - { - $this->_usecase = service('factory.usecase') - ->get($this->_resource(), 'options'); - } - - /** - * Get options for a resource. - * - * OPTIONS /api/foo - * - * @return void - */ - public function action_options_index() - { - $this->_usecase = service('factory.usecase') - ->get($this->_resource(), 'options') - ->setIdentifiers($this->_identifiers()); - } - - /** - * Create An Entity - * - * POST /api/foo - * - * @return void - */ - public function action_post_index_collection() - { - $this->_usecase = service('factory.usecase') - ->get($this->_resource(), 'create') - ->setPayload($this->_payload()); - } - - /** - * Retrieve All Entities - * - * GET /api/foo - * - * @return void - */ - public function action_get_index_collection() - { - $this->_usecase = service('factory.usecase') - ->get($this->_resource(), 'search') - ->setFilters($this->_filters()); - } - - /** - * Retrieve An Entity - * - * GET /api/foo/:id - * - * @return void - */ - public function action_get_index() - { - $this->_usecase = service('factory.usecase') - ->get($this->_resource(), 'read') - ->setIdentifiers($this->_identifiers()); - } - - /** - * Update An Entity - * - * PUT /api/foo/:id - * - * @return void - */ - public function action_put_index() - { - $this->_usecase = service('factory.usecase') - ->get($this->_resource(), 'update') - ->setIdentifiers($this->_identifiers()) - ->setPayload($this->_payload()); - } - - /** - * Delete An Entity - * - * DELETE /api/foo/:id - * - * @return void - */ - public function action_delete_index() - { - $this->_usecase = service('factory.usecase') - ->get($this->_resource(), 'delete') - ->setIdentifiers($this->_identifiers()); - } - - /** - * Get the required scope for this endpoint. - * @return string - */ - abstract protected function _scope(); - - /** - * Get the resource name for this endpoint. Defaults to the scope name. - * @return string - */ - protected function _resource() - { - return $this->_scope(); - } - - /** - * Get the request access method - * - * Allows controllers to customize how different methods are treated. - * - * @return string - */ - protected function _get_access_method() - { - return strtolower($this->request->method()); - } - - /** - * Determines if this request can skip the authorization check. - * - * @return bool - */ - protected function _is_auth_required() - { - // Auth is not required for the OPTIONS method, because auth headers are - // not present in OPTIONS requests. - // We don't require them for GET either, since Authorizer will reject - // requests where anonymous users don't have access - return (!in_array($this->request->method(), [Request::OPTIONS, Request::GET])); - } - - /** - * Check if access is allowed - * Checks if oauth token and user permissions - * - * @return bool - * @throws HTTP_Exception|OAuth_Exception - */ - protected function _check_access() - { - $server = service('oauth.server.resource'); - - // Using an "Authorization: Bearer xyz" header is required, except for GET requests - $require_header = $this->request->method() !== Request::GET; - $required_scope = $this->_scope(); - - // Hack: Make sure request method is populated during testing - $_SERVER['REQUEST_METHOD'] = $this->request->method(); - - try - { - $server->isValid($require_header); - if ($required_scope) - { - $server->hasScope($required_scope, true); - } - } - catch (OAuth2Exception $e) - { - if (!$this->_is_auth_required() AND - $e instanceof MissingAccessTokenException) - { - // A token is not required, so a missing token is not a critical error. - return; - } - - // Auth server returns an indexed array of headers, along with the server - // status as a header, which must be converted to use with Kohana. - $raw_headers = $server::getExceptionHttpHeaders($server::getExceptionType($e->getCode())); - - $status = 400; - $headers = array(); - foreach ($raw_headers as $header) - { - if (preg_match('#^HTTP/1.1 (\d{3})#', $header, $matches)) - { - $status = (int) $matches[1]; - } - else - { - list($name, $value) = explode(': ', $header); - $headers[$name] = $value; - } - } - - $exception = HTTP_Exception::factory($status, $e->getMessage()); - if ($status === 401) - { - // Pass through additional WWW-Authenticate headers, but only for - // HTTP 401 Unauthorized responses! - $exception->headers($headers); - } - throw $exception; - } - } - - /** - * Parse the request... - */ - protected function _parse_request() - { - // Override the method if needed. - $this->request->method(Arr::get( - $_SERVER, - 'HTTP_X_HTTP_METHOD_OVERRIDE', - $this->request->method() - )); - - // Is that a valid method? - if ( ! isset($this->_action_map[$this->request->method()])) - { - throw HTTP_Exception::factory(405, 'The :method method is not supported. Supported methods are :allowed_methods', array( - ':method' => $this->request->method(), - ':allowed_methods' => implode(', ', array_keys($this->_action_map)), - )) - ->allowed(array_keys($this->_action_map)); - } - - // Get the basic verb based action.. - $action = $this->_action_map[$this->request->method()]; - - // If this is a custom action, lets make sure we use it. - if ($this->request->action() != '_none') - { - $action .= '_'.$this->request->action(); - } - - // If we are acting on a collection, append _collection to the action name. - if ($this->request->param('id', FALSE) === FALSE - AND $this->request->param('locale', FALSE) === FALSE) - { - $action .= '_collection'; - } - - // Override the action - $this->request->action($action); - - if (! method_exists($this, 'action_'.$action)) - { - // TODO: filter 'Allow' header to only return implemented methods - throw HTTP_Exception::factory(405, 'The :method method is not supported. Supported methods are :allowed_methods', array( - ':method' => $this->request->method(), - ':allowed_methods' => implode(', ', array_keys($this->_action_map)), - )) - ->allowed(array_keys($this->_action_map)); - } - - // Are we the expecting body content as part of the request? - if (in_array($this->request->method(), $this->_methods_with_body_content)) - { - $this->_parse_request_body(); - } - } - - /** - * Get the identifiers to pass to the usecase. Defaults to the request route params. - * @return array - */ - protected function _identifiers() - { - return $this->request->param(); - } - - /** - * Get the filters to pass to the usecase. Defaults to the request query params. - * @return array - */ - protected function _filters() - { - return $this->request->query(); - } - - /** - * Get the payload to pass to the usecase. Defaults to the request query params. - * @return array - */ - protected function _payload() - { - return $this->_request_payload; - } - - protected $json_errors = [ - JSON_ERROR_DEPTH => 'Maximum stack depth exceeded', - JSON_ERROR_STATE_MISMATCH => 'Underflow or the modes mismatch', - JSON_ERROR_CTRL_CHAR => 'Unexpected control character found', - JSON_ERROR_SYNTAX => 'Syntax error, malformed JSON', - JSON_ERROR_UTF8 => 'Malformed UTF-8 characters, possibly incorrectly encoded', - ]; - - /** - * If the request has a JSON body, parse it into native type. - * - * @todo Support more than just JSON - * @throws HTTP_Exception_400 - */ - protected function _parse_request_body() - { - $payload = json_decode($this->request->body(), true); - - // Ensure there were no JSON errors - $error = json_last_error(); - if ($error AND $error !== JSON_ERROR_NONE) - { - throw new HTTP_Exception_400('Invalid json supplied. Error: \':error\'. \':json\'', array( - ':json' => $this->request->body(), - ':error' => Arr::get($this->json_errors, $error, 'Unknown error'), - )); - } - - // Ensure JSON object/array was supplied, not string etc - if ( ! is_array($payload) AND ! is_object($payload) ) - { - throw new HTTP_Exception_400('Invalid json supplied. Error: \'JSON must be array or object\'. \':json\'', array( - ':json' => $this->request->body(), - )); - } - - $this->_request_payload = $payload; - } - - /** - * Execute the usecase that the controller prepared. - * @throws HTTP_Exception_400 - * @throws HTTP_Exception_403 - * @throws HTTP_Exception_404 - * @return void - */ - protected function _execute_usecase() - { - try - { - // Attempt to execute the usecase to get the response - $this->_response_payload = $this->_usecase->interact(); - } - catch (Ushahidi\Core\Exception\NotFoundException $e) - { - throw new HTTP_Exception_404($e->getMessage()); - } - catch (Ushahidi\Core\Exception\AuthorizerException $e) - { - // If we don't have an Authorization header, return 401 - if (!$this->request->headers('Authorization')) { - throw HTTP_Exception::factory(401, 'The request is missing an access token in either the Authorization header or the access_token request parameter.')->headers(['www-authenticate' => 'Bearer realm=""']); - } else { - // Otherwise throw a 403 - throw new HTTP_Exception_403($e->getMessage()); - } - } - catch (Ushahidi\Core\Exception\ValidatorException $e) - { - throw new HTTP_Exception_422( - 'Validation Error', - NULL, - $e - ); - } - catch (\InvalidArgumentException $e) - { - throw new HTTP_Exception_400( - 'Bad request: :error', - [':error' => $e->getMessage()] - ); - } - } - - /** - * Prepare response headers and body, formatted based on user request. - * @throws HTTP_Exception_400 - * @throws HTTP_Exception_500 - * @return void - */ - protected function _prepare_response() - { - if ($this->_usecase) - { - // Run the usecase - $this->_execute_usecase(); - } - - // Add CORS headers to the response - $this->add_cors_headers($this->response); - // Should we prevent this request from being cached? - if ( ! in_array($this->request->method(), $this->_cacheable_methods)) - { - $this->response->headers('Cache-Control', 'no-cache, no-store, max-age=0, must-revalidate'); - } - - // Use JSON if the request method is OPTIONS - if ($this->request->method() === Request::OPTIONS) - { - $type = 'json'; - } else { - //...Get the requested response format, use JSON for default - $type = strtolower($this->request->query('format')) ?: 'json'; - } - - try - { - $format = service("formatter.output.$type"); - - $body = $format($this->_response_payload); - $mime = $format->getMimeType(); - - if ($type === 'jsonp') - { - // Prevent Opera and Chrome from executing the response as anything - // other than JSONP, see T455. - $this->response->headers('X-Content-Type-Options', 'nosniff'); - } - - $this->response->headers('Content-Type', $mime); - - if (empty($this->_response_payload)) - { - // If the payload is empty, return a 204 - // https://tools.ietf.org/html/rfc7231#section-6.3.5 - $this->response->status(204); - } else { - // If we have a payload set response body - $this->response->body($body); - } - } - catch (Aura\Di\Exception\ServiceNotFound $e) - { - throw new HTTP_Exception_400( - 'Unknown response format: :format', - [':format' => $type] - ); - } - catch (InvalidArgumentException $e) - { - throw new HTTP_Exception_400( - 'Bad formatting parameters: :message', - [':message' => $e->getMessage()] - ); - } - catch (Ushahidi\Core\Exception\FormatterException $e) - { - throw new HTTP_Exception_500( - 'Error while formatting response: :message', - [':message' => $e->getMessage()] - ); - } - } -} diff --git a/application/config/environments/development/.gitignore b/application/config/environments/development/.gitignore deleted file mode 100644 index 50b9fa4bce..0000000000 --- a/application/config/environments/development/.gitignore +++ /dev/null @@ -1,5 +0,0 @@ -# Ignore all files -* -# Except this file -!.gitignore -# To prevent cache files from ever being committed into the git repo. diff --git a/application/config/imagefly.php b/application/config/imagefly.php deleted file mode 100644 index 84b039bad0..0000000000 --- a/application/config/imagefly.php +++ /dev/null @@ -1,67 +0,0 @@ - - * @package Ushahidi\Application\Config - * @copyright 2013 Ushahidi - * @license https://www.gnu.org/licenses/agpl-3.0.html GNU Affero General Public License Version 3 (AGPL3) - */ - -return array -( - /** - * Number of seconds before the browser checks the server for a new version of the modified image. - */ - 'cache_expire' => 604800, - /** - * Path to the image cache directory you would like to use, don't forget the trailing slash! - */ - 'cache_dir' => APPPATH.'cache'.DIRECTORY_SEPARATOR.'imagefly'.DIRECTORY_SEPARATOR, - /** - * Path to the image cache directory you would like to use, don't forget the trailing slash! - */ - 'source_dir' => APPPATH.'media'.DIRECTORY_SEPARATOR, - /** - * Mimic the source file folder structure within the cache directory. - * Useful if you want to keep track of cached files and folders to perhaps periodically clear some cache folders but not others. - */ - 'mimic_source_dir' => TRUE, - /** - * The default quality of images when not specified in the URL - */ - 'quality' => 80, - /** - * If the image should be scaled up beyond it's original dimensions on resize. - */ - 'scale_up' => FALSE, - /** - * Will only allow param configurations set in the presets. - * Best enabled on production sites to reduce spamming of different sized images on the server. - */ - 'enforce_presets' => TRUE, - /** - * Imagefly params that are allowed when enforce_presets is set to TRUE - * Any other param configuration will throw a 404 error. - */ - 'presets' => array( - 'w800', - 'w70' - ), - /** - * Configure one or more watermarks. Each configuration key can be passed as a param through an Imagefly URL to apply the watermark. - * If no offset is specified, the center of the axis will be used. - * If an offset of TRUE is specified, the bottom of the axis will be used. - */ - 'watermarks' => array( - /* Example - 'custom_watermark' => array( - 'image' => 'path/to/watermark.png', - 'offset_x' => TRUE, - 'offset_y' => TRUE, - 'opacity' => 80 - ) - */ - ) -); diff --git a/application/config/init.php b/application/config/init.php deleted file mode 100644 index cee00d5a0c..0000000000 --- a/application/config/init.php +++ /dev/null @@ -1,34 +0,0 @@ - - * @package Ushahidi\Application\Config - * @copyright 2013 Ushahidi - * @license https://www.gnu.org/licenses/agpl-3.0.html GNU Affero General Public License Version 3 (AGPL3) - */ - -/** - * Initialize Kohana, setting the default options. - * - * The following options are available: - * - * - string base_url path, and optionally domain, of your application NULL - * - string index_file name of your index file, usually "index.php" index.php - * - string charset internal character set used for input and output utf-8 - * - string cache_dir set the internal cache directory APPPATH/cache - * - integer cache_life lifetime, in seconds, of items cached 60 - * - boolean errors enable or disable error handling TRUE - * - boolean profile enable or disable internal profiling TRUE - * - boolean caching enable or disable internal caching FALSE - * - boolean expose set the X-Powered-By header FALSE - */ -return array( - 'base_url' => '/', - 'index_file' => FALSE, - 'charset' => 'utf-8', - 'errors' => false, - 'profile' => FALSE, - 'caching' => FALSE, -); \ No newline at end of file diff --git a/application/config/media.php b/application/config/media.php deleted file mode 100644 index bfb336700f..0000000000 --- a/application/config/media.php +++ /dev/null @@ -1,49 +0,0 @@ - - * @package Ushahidi\Application\Config - * @copyright 2013 Ushahidi - * @license https://www.gnu.org/licenses/agpl-3.0.html GNU Affero General Public License Version 3 (AGPL3) - */ - -return array( - - // The public accessible directory where the file will be copied - 'public_dir' => DOCROOT.'media//', - // Write the files to the public directory when in production - 'cache' => FALSE, //Kohana::$environment === Kohana::PRODUCTION, - /** - * The UID for media files. - * This should be unique across the entire project because from a css file - * you want to be able to use relative paths to images. - * Your css file would not know where an image is if it had a UID of its own. - * App versions and repository revisions are good UIDs to use. - */ - 'uid' => NULL, // Replace this later - needs to get passed into app to change paths there too. - // 'uid' => "3-0-dev", - - // Where to upload media files eg. images. Take note of the trailing slash. - // This should be in the Document root. - 'media_upload_dir' => APPPATH.'media'.DIRECTORY_SEPARATOR.'uploads'.DIRECTORY_SEPARATOR, - - // Width to be used to resize the image to a medium size - 'image_medium_width' => 800, - - // Height to be used to resize the image to a medium size. NULL by default - // so the image's aspect ratio is maintain when resizing it. - 'image_medium_height' => NULL, - - // Width to be used to resize the image to a thumbnail size - 'image_thumbnail_width' => 70, - - // Height to be used to resize the image to a thumbnail size. NULL by default - // so the image's aspect ratio is maintain when resizing it. - 'image_thumbnail_height' => NULL, - - // Maximum file upload size in bytes. Remember this figure should not be larger - // than the maximum file upload size set on the server. 1Mb by default. - 'max_upload_bytes' => '1048576', -); diff --git a/application/config/modules.php b/application/config/modules.php deleted file mode 100644 index f1b0ab064e..0000000000 --- a/application/config/modules.php +++ /dev/null @@ -1,26 +0,0 @@ - - * @package Ushahidi\Application\Config - * @copyright 2013 Ushahidi - * @license https://www.gnu.org/licenses/agpl-3.0.html GNU Affero General Public License Version 3 (AGPL3) - */ - -return array( - // Custom modules - // 'acme' => MODPATH.'acme', - - // Submodules - // 'data-provider' => MODPATH.'data-provider', - - // Vendor modules - 'imagefly' => VENPATH.'bodom78/kohana-imagefly', // Dynamic image generation - 'media' => VENPATH.'zeelot/kohana-media', - - // Kohana modules - 'cache' => MODPATH.'cache', // Caching with multiple backends - 'image' => MODPATH.'image', // Image manipulation -); diff --git a/application/config/session.php b/application/config/session.php deleted file mode 100644 index a32b9514dc..0000000000 --- a/application/config/session.php +++ /dev/null @@ -1,17 +0,0 @@ - - * @package Ushahidi\Application\Config - * @copyright 2013 Ushahidi - * @license https://www.gnu.org/licenses/agpl-3.0.html GNU Affero General Public License Version 3 (AGPL3) - */ - -return array( - 'native' => array( - // @TODO change this to be project-specific - 'name' => 'ushahidi', - ), -); \ No newline at end of file diff --git a/application/kohana.php b/application/kohana.php deleted file mode 100644 index d84b766458..0000000000 --- a/application/kohana.php +++ /dev/null @@ -1,117 +0,0 @@ -= 5.3, it is recommended to disable - * deprecated notices. Disable with: E_ALL & ~E_DEPRECATED - */ -error_reporting(E_ALL | E_STRICT); - -/** - * End of standard configuration! Changing any of the code below should only be - * attempted by those with a working knowledge of Kohana internals. - * - * @see http://kohanaframework.org/guide/using.configuration - */ - -// Make sure plugins exists before we define PLUGINPATH -// If it doesn't exist realpath($plugins) returns FALSE -// FALSE.DIRECTORY_SEPARATOR = '/' .. mayhem insues. -if (realpath($plugins)) -{ - define('PLUGINPATH', realpath($plugins).DIRECTORY_SEPARATOR); -} - -// Define the absolute paths for configured directories -define('APPPATH', realpath($application).DIRECTORY_SEPARATOR); -define('MODPATH', realpath($modules).DIRECTORY_SEPARATOR); -define('SYSPATH', realpath($system).DIRECTORY_SEPARATOR); -define('VENPATH', realpath($vendor).DIRECTORY_SEPARATOR); -// Set the full path to the docroot -if (!defined('DOCROOT')) -{ - define('DOCROOT', realpath(__DIR__ . '/../httpdocs') . DIRECTORY_SEPARATOR); -} - -// Clean up the configuration vars -unset($application, $modules, $system); - -/** - * Define the start time of the application, used for profiling. - */ -if ( ! defined('KOHANA_START_TIME')) -{ - define('KOHANA_START_TIME', microtime(TRUE)); -} - -/** - * Define the memory usage at the start of the application, used for profiling. - */ -if ( ! defined('KOHANA_START_MEMORY')) -{ - define('KOHANA_START_MEMORY', memory_get_usage()); -} - -// Ushahidi: load transitional code -require APPPATH.'../src/Init'.EXT; - -// Load dotenv -if (is_file(APPPATH.'../.env')) { - try { - (new Dotenv\Dotenv(APPPATH.'/../'))->load(); - } catch (Dotenv\Exception\InvalidPathException $e) { - // - } -} - -// Bootstrap the application -require APPPATH.'bootstrap'.EXT; diff --git a/application/logs/.gitignore b/application/logs/.gitignore deleted file mode 100755 index 50b9fa4bce..0000000000 --- a/application/logs/.gitignore +++ /dev/null @@ -1,5 +0,0 @@ -# Ignore all files -* -# Except this file -!.gitignore -# To prevent cache files from ever being committed into the git repo. diff --git a/application/media/uploads/.gitignore b/application/media/uploads/.gitignore deleted file mode 100644 index 50b9fa4bce..0000000000 --- a/application/media/uploads/.gitignore +++ /dev/null @@ -1,5 +0,0 @@ -# Ignore all files -* -# Except this file -!.gitignore -# To prevent cache files from ever being committed into the git repo. diff --git a/application/routes/default.php b/application/routes/default.php deleted file mode 100644 index 8e24a7c6e0..0000000000 --- a/application/routes/default.php +++ /dev/null @@ -1,315 +0,0 @@ - - * @package Ushahidi\Application\Config - * @copyright 2013 Ushahidi - * @license https://www.gnu.org/licenses/agpl-3.0.html GNU Affero General Public License Version 3 (AGPL3) - */ - -/** - * API version number - */ -$apiVersion = '3'; -$apiBase = 'api/v' . $apiVersion . '/'; - -/** - * Custom media router. - */ -Route::set('media', 'media/', array( - 'filepath' => '.*', // Pattern to match the file path - )) - ->defaults(array( - 'controller' => 'Media', - 'action' => 'serve', - )); - -/** - * Path to CSV uploads. - */ -Route::set('csv', $apiBase . 'csv(/)', array( - 'id' => '\d+' - )) - ->defaults(array( - 'controller' => 'CSV', - 'action' => 'index', - 'directory' => 'Api' - )); - -/** - * Path to CSV imports. - */ -Route::set('csv-import', $apiBase . 'csv//import', array( - 'csv_id' => '\d+' - )) - ->defaults(array( - 'controller' => 'Import', - 'action' => 'index', - 'directory' => 'Api/CSV' - )); - -/** - * Set Posts API SubRoute - */ -Route::set('collections-posts', $apiBase . 'collections//posts(/)', - array( - 'set_id' => '\d+', - 'id' => '\d+' - )) - ->defaults(array( - 'action' => 'index', - 'controller' => 'Posts', - 'directory' => 'Api/Collections' - )); - - -/** - * Export Posts API SubRoute - */ - Route::set('export', $apiBase . 'posts/export') - ->defaults(array( - 'action' => 'index', - 'controller' => 'Export', - 'directory' => 'Api/Posts' - )); - -/** - * Stats Posts API SubRoute - */ -Route::set('post-stats', $apiBase . 'posts/stats') - ->defaults(array( - 'action' => 'stats', - 'controller' => 'Posts', - 'directory' => 'Api' - )); - -/** - * Lock Posts API SubRoute - */ -Route::set('post-lock', $apiBase . 'posts(/)/lock(/)', - array( - 'post_id' => '\d+', - 'lock_id' => '\d+' - )) - ->defaults(array( - 'action' => 'index', - 'controller' => 'Lock', - 'directory' => 'Api/Posts' - )); - - -/** - * GeoJSON API SubRoute - */ -Route::set('geojson', $apiBase . 'posts/geojson(///)', - array( - 'zoom' => '\d+', - 'x' => '\d+', - 'y' => '\d+', - )) - ->defaults(array( - 'action' => 'index', - 'controller' => 'GeoJSON', - 'directory' => 'Api/Posts' - )); - -/** - * GeoJSON API SubRoute - */ -Route::set('geojson-post-id', $apiBase . 'posts//geojson', - array( - 'id' => '\d+', - 'zoom' => '\d+', - 'x' => '\d+', - 'y' => '\d+', - )) - ->defaults(array( - 'action' => 'index', - 'controller' => 'GeoJSON', - 'directory' => 'Api/Posts' - )); - -/** - * Posts API SubRoute - */ -Route::set('posts', $apiBase . 'posts//(/)', - array( - 'parent_id' => '\d+', - 'id' => '\d+' - )) - ->defaults(array( - 'action' => 'index', - 'directory' => 'Api/Posts' - )); - -/** - * Base Ushahidi API Route - */ -Route::set('current-user', $apiBase . 'users/me') - ->defaults(array( - 'action' => 'me', - 'directory' => 'Api', - 'controller' => 'Users', - 'id' => 'me' - )); - -/** - * Password Reset Route - */ -Route::set('passwordreset-api', $apiBase . 'passwordreset(/)', [ - 'action' => '(?:index|confirm)' - ]) - ->defaults([ - 'action' => 'index', - 'directory' => 'Api', - 'controller' => 'PasswordReset', - ]); - -/** - * Config API Route - */ -Route::set('config-api', $apiBase . 'config(/(/))', - array( - 'id' => '[a-zA-Z_-]+', - 'key' => '[a-zA-Z_.-]+' - )) - ->defaults(array( - 'action' => 'index', - 'directory' => 'Api', - 'controller' => 'Config', - )); - -/** - * Messages API Route - */ -Route::set('messages-api', $apiBase . 'messages(/(/))', - array( - 'id' => '\d+' - )) - ->defaults(array( - 'action' => 'index', - 'directory' => 'Api', - 'controller' => 'Messages' - )); - -/** - * Dataproviders API Route - */ -Route::set('dataproviders-api', $apiBase . 'dataproviders(/)', - array( - 'id' => '[a-zA-Z_-]+' - )) - ->defaults(array( - 'action' => 'index', - 'directory' => 'Api', - 'controller' => 'DataProviders', - )); - -/** - * SavedSearches API Route - */ -Route::set('savedsearches-api', $apiBase . 'savedsearches(/)', - array( - 'id' => '\d+' - )) - ->defaults(array( - 'action' => 'index', - 'directory' => 'Api', - 'controller' => 'SavedSearches', - )); - -/** - * Post stats API route - */ -// Route::set('post-stats-api', $apiBase . 'stats/posts') -// ->defaults(array( -// 'action' => 'index', -// 'directory' => 'Api/Stats', -// 'controller' => 'Posts', -// )); - -/** - * Base Ushahidi API Route - */ -Route::set('api', $apiBase . '((/))', - array( - 'id' => '\d+' - )) - ->defaults(array( - 'action' => 'index', - 'directory' => 'Api' - )); - -/** - * Forms API SubRoute - */ -Route::set('forms', $apiBase . 'forms(/)/(/)', - array( - 'form_id' => '\d+', - 'id' => '\d+' - )) - ->defaults(array( - 'action' => 'index', - 'directory' => 'Api/Forms' - )); - - -/** - * Translations API SubRoute - */ -Route::set('translations', $apiBase . 'posts//translations(/)', - array( - 'parent_id' => '\d+', - 'locale' => '[a-zA-Z_]+' - )) - ->defaults(array( - 'action' => 'index', - 'controller' => 'Translations', - 'directory' => 'Api/Posts' - )); - -/** - * Migration Route - */ -Route::set('migration', $apiBase . 'migration/', - array( - 'action' => '(?:status|rollback|migrate)', - )) - ->defaults(array( - 'action' => 'rollback', - 'controller' => 'Migration', - 'directory' => 'Api' - )); - -/** - * Migration migrate Route - */ -Route::set('migration-migrate', 'migrate') - ->defaults(array( - 'controller' => 'Migrate' - )); - -/** - * OAuth Route - * Have to add this manually because the class is OAuth not Oauth - */ -Route::set('oauth', 'oauth(/)', - array( - 'action' => '(?:index|authorize|token)', - )) - ->defaults(array( - 'controller' => 'OAuth', - 'action' => 'index', - )); - - -/** - * Default Route - */ -Route::set('default', '('.$apiBase.')') - ->defaults(array( - 'controller' => 'Index', - 'action' => 'index', - 'directory' => 'Api' - )); diff --git a/application/views/error/api.php b/application/views/error/api.php deleted file mode 100644 index c8365bf4d2..0000000000 --- a/application/views/error/api.php +++ /dev/null @@ -1,47 +0,0 @@ - - * @package Ushahidi\Application - * @copyright 2013 Ushahidi - * @license https://www.gnu.org/licenses/agpl-3.0.html GNU Affero General Public License Version 3 (AGPL3) - */ - -$errors = []; -$options = null; - -// Build initial error -$error = [ - 'status' => $code, - 'title' => $message, - 'message' => $message, -]; - -// If we're in dev mode -if (Kohana::$environment === Kohana::DEVELOPMENT) { - // .. generate pretty json - $options = JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES; - // .. and include extra debug info - $error = $error + compact('class', 'file', 'line', 'trace'); -} - -// Add first error object.. -$errors[] = $error; - -// then any additional errors (ie. validation errors) -if (method_exists($e, 'getErrors')) { - foreach ($e->getErrors() as $key => $value) { - $errors[] = [ - 'status' => $code, - 'title' => $value, - 'message' => $value, - 'source' => [ - 'pointer' => "/" . $key - ] - ]; - } -} - -// Convert JSON and dump output -echo json_encode(['errors' => $errors], $options); diff --git a/application/views/minion/task/ushahidi/form_json.php b/application/views/minion/task/ushahidi/form_json.php deleted file mode 100644 index 8f1e48fb82..0000000000 --- a/application/views/minion/task/ushahidi/form_json.php +++ /dev/null @@ -1,97 +0,0 @@ -{ - "name":"Classic Report Form", - "type":"report", - "description":"Classic Ushahidi 2.x Report Form", - "groups":[ - { - "label":"Incident Fields", - "priority": 1, - "attributes":[ - { - "key":"original_id", - "label":"Original ID", - "type":"int", - "input":"text", - "required":false, - "priority":0, - "default":"", - "options":{} - }, - { - "key":"date", - "label":"Date", - "type":"datetime", - "input":"date", - "required":true, - "priority":0, - "default":"", - "options":{} - }, - { - "key":"location_name", - "label":"Location Name", - "type":"varchar", - "input":"text", - "required":false, - "priority":1 - }, - { - "key":"location", - "label":"Location", - "type":"point", - "input":"location", - "required":false, - "priority":2 - }, - { - "key":"verified", - "label":"Verified", - "type":"int", - "input":"checkbox", - "required":false, - "priority":3 - }, - { - "key":"source", - "label":"Source", - "type":"varchar", - "input":"select", - "required":false, - "priority":4, - "default":"Web", - "options":[ - "Unknown", - "Web", - "SMS", - "Email", - "Twitter" - ] - } - ] - }, - { - "label":"Media Fields", - "priority": 2, - "attributes":[ - { - "key":"news", - "label":"News", - "type":"varchar", - "input":"text", - "required":false, - "priority":0, - "cardinality":0 - }, - { - "key":"video", - "label":"Video", - "type":"varchar", - "input":"text", - "required":false, - "priority":2, - "cardinality":0 - } - ] - } - ] -} \ No newline at end of file diff --git a/application/views/minion/task/ushahidi/import2x.php b/application/views/minion/task/ushahidi/import2x.php deleted file mode 100644 index ce21813fb4..0000000000 --- a/application/views/minion/task/ushahidi/import2x.php +++ /dev/null @@ -1,13 +0,0 @@ - - -Created 'Classic Report Form', ID: . -Imported tags. -Imported posts. -Imported users. - - -Max memory usage - - - - diff --git a/bootstrap/app.php b/bootstrap/app.php index 578043bc8e..7d5b6dd017 100644 --- a/bootstrap/app.php +++ b/bootstrap/app.php @@ -8,8 +8,9 @@ // } -// Initialize the Kohana application -require_once __DIR__ . '/../application/kohana.php'; + +// Ushahidi: load transitional code +require_once __DIR__.'/../src/Init.php'; $app = require __DIR__.'/lumen.php'; diff --git a/bootstrap/lumen.php b/bootstrap/lumen.php index 1b7752020e..be62b7788e 100644 --- a/bootstrap/lumen.php +++ b/bootstrap/lumen.php @@ -15,7 +15,7 @@ realpath(__DIR__.'/../') ); -// $app->withFacades(); +$app->withFacades(); $app->withEloquent(); diff --git a/composer.json b/composer.json index 9114d3c4e0..28e42a6f62 100644 --- a/composer.json +++ b/composer.json @@ -17,22 +17,16 @@ "require": { "php": ">=7.0", "aura/di": "2.2", - "bodom78/kohana-imagefly": "dev-master", "league/flysystem-aws-s3-v3": "~1.0", "league/flysystem-rackspace": "~1.0", "league/flysystem": "~1.0", "ircmaxell/password-compat": "^1.0.4", "intercom/intercom-php": "^3.1.2", "abraham/twitteroauth": "^0.5.3", - "kohana/core" : "3.3.3.1@dev", - "kohana/cache" : "3.3.*@dev", - "kohana/image" : "3.3.*@dev", - "kohana/minion" : "3.3.*@dev", "ohanzee/database": "dev-namespaces", "robmorgan/phinx": "~0.8.0", "symm/gisconverter": "~1.0.5", "vlucas/phpdotenv": "~2.2", - "zeelot/kohana-media": "1.3.*@dev", "ext-curl": "*", "ext-gd": "*", "ext-json": "*", diff --git a/composer.lock b/composer.lock index 32235b4f2b..d8761af4b7 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "content-hash": "3047df702d54919d85a77cce658dc43c", + "content-hash": "640be1069cca60ec2bee688f4d43545d", "packages": [ { "name": "abraham/twitteroauth", @@ -308,164 +308,6 @@ ], "time": "2017-06-02T21:56:31+00:00" }, - { - "name": "bodom78/kohana-imagefly", - "version": "dev-master", - "source": { - "type": "git", - "url": "https://github.com/Bodom78/kohana-imagefly.git", - "reference": "f8a96d5cb54226f4e4c14a19d164a5722eceb012" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/Bodom78/kohana-imagefly/zipball/f8a96d5cb54226f4e4c14a19d164a5722eceb012", - "reference": "f8a96d5cb54226f4e4c14a19d164a5722eceb012", - "shasum": "" - }, - "require": { - "kohana/core": ">=3.2", - "php": ">=5.3.3" - }, - "type": "library", - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Fady Khalife", - "homepage": "http://fkportfolio.com", - "role": "developer" - } - ], - "description": "Create resized / cropped images directly through url parameters.", - "homepage": "https://github.com/bodom78/kohana-imagefly", - "keywords": [ - "crop", - "image", - "kohana", - "resize", - "watermark" - ], - "time": "2014-08-11T02:52:57+00:00" - }, - { - "name": "composer/installers", - "version": "v1.4.0", - "source": { - "type": "git", - "url": "https://github.com/composer/installers.git", - "reference": "9ce17fb70e9a38dd8acff0636a29f5cf4d575c1b" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/composer/installers/zipball/9ce17fb70e9a38dd8acff0636a29f5cf4d575c1b", - "reference": "9ce17fb70e9a38dd8acff0636a29f5cf4d575c1b", - "shasum": "" - }, - "require": { - "composer-plugin-api": "^1.0" - }, - "replace": { - "roundcube/plugin-installer": "*", - "shama/baton": "*" - }, - "require-dev": { - "composer/composer": "1.0.*@dev", - "phpunit/phpunit": "4.1.*" - }, - "type": "composer-plugin", - "extra": { - "class": "Composer\\Installers\\Plugin", - "branch-alias": { - "dev-master": "1.0-dev" - } - }, - "autoload": { - "psr-4": { - "Composer\\Installers\\": "src/Composer/Installers" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Kyle Robinson Young", - "email": "kyle@dontkry.com", - "homepage": "https://github.com/shama" - } - ], - "description": "A multi-framework Composer library installer", - "homepage": "https://composer.github.io/installers/", - "keywords": [ - "Craft", - "Dolibarr", - "Eliasis", - "Hurad", - "ImageCMS", - "Kanboard", - "Lan Management System", - "MODX Evo", - "Mautic", - "Maya", - "OXID", - "Plentymarkets", - "Porto", - "RadPHP", - "SMF", - "Thelia", - "WolfCMS", - "agl", - "aimeos", - "annotatecms", - "attogram", - "bitrix", - "cakephp", - "chef", - "cockpit", - "codeigniter", - "concrete5", - "croogo", - "dokuwiki", - "drupal", - "eZ Platform", - "elgg", - "expressionengine", - "fuelphp", - "grav", - "installer", - "itop", - "joomla", - "kohana", - "laravel", - "lavalite", - "lithium", - "magento", - "mako", - "mediawiki", - "modulework", - "moodle", - "osclass", - "phpbb", - "piwik", - "ppi", - "puppet", - "reindex", - "roundcube", - "shopware", - "silverstripe", - "sydes", - "symfony", - "typo3", - "wordpress", - "yawik", - "zend", - "zikula" - ], - "time": "2017-08-09T07:53:48+00:00" - }, { "name": "ddeboer/data-import", "version": "dev-master", @@ -2468,238 +2310,6 @@ ], "time": "2014-11-20T16:49:30+00:00" }, - { - "name": "kohana/cache", - "version": "v3.3.6", - "source": { - "type": "git", - "url": "https://github.com/kohana/cache.git", - "reference": "a93af69561bb789b01f12080517005268f974be7" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/kohana/cache/zipball/a93af69561bb789b01f12080517005268f974be7", - "reference": "a93af69561bb789b01f12080517005268f974be7", - "shasum": "" - }, - "require": { - "composer/installers": "~1.0", - "kohana/core": ">=3.3", - "php": ">=5.3.3" - }, - "require-dev": { - "kohana/core": "3.3.*@dev", - "kohana/koharness": "*@dev", - "kohana/unittest": "3.3.*@dev" - }, - "type": "kohana-module", - "extra": { - "branch-alias": { - "dev-3.3/develop": "3.3.x-dev", - "dev-3.4/develop": "3.4.x-dev" - }, - "installer-paths": { - "vendor/{$vendor}/{$name}": [ - "type:kohana-module" - ] - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Kohana Team", - "email": "team@kohanaframework.org", - "homepage": "http://kohanaframework.org/team", - "role": "developer" - } - ], - "description": "The official Kohana cache management module", - "homepage": "http://kohanaframework.org", - "keywords": [ - "cache", - "framework", - "kohana" - ], - "time": "2016-03-30T09:53:56+00:00" - }, - { - "name": "kohana/core", - "version": "v3.3.3.1", - "source": { - "type": "git", - "url": "https://github.com/kohana/core.git", - "reference": "fa66e193b56cbf4bc36aa16caec31feccf31e92a" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/kohana/core/zipball/fa66e193b56cbf4bc36aa16caec31feccf31e92a", - "reference": "fa66e193b56cbf4bc36aa16caec31feccf31e92a", - "shasum": "" - }, - "require": { - "php": ">=5.3.3" - }, - "require-dev": { - "kohana/koharness": "*@dev", - "kohana/unittest": "3.3.*@dev" - }, - "suggest": { - "ext-curl": "*", - "ext-http": "*", - "ext-mcrypt": "*" - }, - "type": "library", - "extra": { - "installer-paths": { - "vendor/{$vendor}/{$name}": [ - "type:kohana-module" - ] - }, - "branch-alias": { - "dev-3.3/develop": "3.3.x-dev", - "dev-3.4/develop": "3.4.x-dev" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Kohana Team", - "email": "team@kohanaframework.org", - "homepage": "http://kohanaframework.org/team", - "role": "developer" - } - ], - "description": "Core system classes for the Kohana application framework", - "homepage": "http://kohanaframework.org", - "keywords": [ - "framework", - "kohana" - ], - "time": "2014-12-11T02:17:12+00:00" - }, - { - "name": "kohana/image", - "version": "v3.3.6", - "source": { - "type": "git", - "url": "https://github.com/kohana/image.git", - "reference": "40f196dd9246a35988e17fdd211bd312687d14e8" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/kohana/image/zipball/40f196dd9246a35988e17fdd211bd312687d14e8", - "reference": "40f196dd9246a35988e17fdd211bd312687d14e8", - "shasum": "" - }, - "require": { - "composer/installers": "~1.0", - "kohana/core": ">=3.3", - "php": ">=5.3.3" - }, - "require-dev": { - "kohana/core": "3.3.*@dev", - "kohana/koharness": "*@dev", - "kohana/unittest": "3.3.*@dev" - }, - "suggest": { - "ext-gd": "*" - }, - "type": "kohana-module", - "extra": { - "branch-alias": { - "dev-3.3/develop": "3.3.x-dev", - "dev-3.4/develop": "3.4.x-dev" - }, - "installer-paths": { - "vendor/{$vendor}/{$name}": [ - "type:kohana-module" - ] - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Kohana Team", - "email": "team@kohanaframework.org", - "homepage": "http://kohanaframework.org/team", - "role": "developer" - } - ], - "description": "The official Kohana module for manipulating images", - "homepage": "http://kohanaframework.org", - "keywords": [ - "framework", - "image", - "kohana" - ], - "time": "2016-03-23T17:12:48+00:00" - }, - { - "name": "kohana/minion", - "version": "v3.3.6", - "source": { - "type": "git", - "url": "https://github.com/kohana/minion.git", - "reference": "afa27b10a75df96f15307ef42e474dc89540c538" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/kohana/minion/zipball/afa27b10a75df96f15307ef42e474dc89540c538", - "reference": "afa27b10a75df96f15307ef42e474dc89540c538", - "shasum": "" - }, - "require": { - "composer/installers": "~1.0", - "kohana/core": ">=3.3", - "php": ">=5.3.3" - }, - "require-dev": { - "kohana/core": "3.3.*@dev", - "kohana/koharness": "*@dev", - "kohana/unittest": "3.3.*@dev" - }, - "type": "kohana-module", - "extra": { - "branch-alias": { - "dev-3.3/develop": "3.3.x-dev", - "dev-3.4/develop": "3.4.x-dev" - }, - "installer-paths": { - "vendor/{$vendor}/{$name}": [ - "type:kohana-module" - ] - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Kohana Team", - "email": "team@kohanaframework.org", - "homepage": "http://kohanaframework.org/team", - "role": "developer" - } - ], - "description": "The official kohana module for running tasks via the CLI", - "homepage": "http://kohanaframework.org", - "keywords": [ - "framework", - "kohana", - "task" - ], - "time": "2016-03-23T17:13:14+00:00" - }, { "name": "laravel/lumen-framework", "version": "v5.5.2", @@ -5713,60 +5323,6 @@ ], "time": "2016-09-01T10:05:43+00:00" }, - { - "name": "zeelot/kohana-media", - "version": "dev-1.3/develop", - "source": { - "type": "git", - "url": "https://github.com/Zeelot/kohana-media.git", - "reference": "2f657c028d6c875017fd37d6b8d1fa3d2e3fe35e" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/Zeelot/kohana-media/zipball/2f657c028d6c875017fd37d6b8d1fa3d2e3fe35e", - "reference": "2f657c028d6c875017fd37d6b8d1fa3d2e3fe35e", - "shasum": "" - }, - "require": { - "kohana/core": ">=3.3", - "php": ">=5.3.3" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-1.3/develop": "1.3.x-dev" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Lorenzo Pisani", - "email": "zeelot3k@gmail.com", - "homepage": "http://zeelot3k.com", - "role": "developer" - }, - { - "name": "Contributors", - "homepage": "https://github.com/Zeelot/kohana-media/graphs/contributors", - "role": "contributor" - } - ], - "description": "Using the Kohana cascading file system to serve media assets", - "homepage": "https://github.com/Zeelot/kohana-media", - "keywords": [ - "assets", - "caching", - "cfs", - "files", - "framework", - "kohana", - "media" - ], - "time": "2014-04-26T16:15:53+00:00" - }, { "name": "zendframework/zend-diactoros", "version": "1.6.1", @@ -8822,13 +8378,7 @@ "aliases": [], "minimum-stability": "dev", "stability-flags": { - "bodom78/kohana-imagefly": 20, - "kohana/core": 20, - "kohana/cache": 20, - "kohana/image": 20, - "kohana/minion": 20, "ohanzee/database": 20, - "zeelot/kohana-media": 20, "league/csv": 20, "ddeboer/data-import": 20, "league/event": 20, diff --git a/config/cdn.php b/config/cdn.php index 0b3f71976f..fe51c24d71 100644 --- a/config/cdn.php +++ b/config/cdn.php @@ -13,7 +13,7 @@ 'local' => [ // Where to upload media files eg. images. Take note of the trailing slash. // This should be in the Document root. - 'media_upload_dir' => APPPATH.'media'.DIRECTORY_SEPARATOR.'uploads'.DIRECTORY_SEPARATOR, + 'media_upload_dir' => 'media/uploads' // app_path('media/uploads/'), ] // AWS S3 v3 CDN config example /* diff --git a/config/media.php b/config/media.php new file mode 100644 index 0000000000..bd61176bab --- /dev/null +++ b/config/media.php @@ -0,0 +1,15 @@ + 'media/uploads', + + // Maximum file upload size in bytes. Remember this figure should not be larger + // than the maximum file upload size set on the server. 1Mb by default. + 'max_upload_bytes' => '1048576', +); diff --git a/application/config/database.php b/config/ohanzee-db.php similarity index 83% rename from application/config/database.php rename to config/ohanzee-db.php index f65b3cca04..938e9bedad 100644 --- a/application/config/database.php +++ b/config/ohanzee-db.php @@ -1,4 +1,4 @@ - getenv('DB_DATABASE'), 'username' => getenv('DB_USERNAME'), 'password' => getenv('DB_PASSWORD'), - 'persistent' => FALSE, + 'persistent' => false, ], 'table_prefix' => '', 'charset' => 'utf8', - 'caching' => TRUE, - 'profiling' => TRUE, + 'caching' => true, + 'profiling' => true, ]; // If multisite is enabled @@ -42,11 +42,11 @@ // Just define basics for default connection 'default' => [ 'type' => 'MySQLi', - 'connection' => [ 'persistent' => FALSE, ], + 'connection' => [ 'persistent' => false, ], 'table_prefix' => '', 'charset' => 'utf8', - 'caching' => TRUE, - 'profiling' => TRUE, + 'caching' => true, + 'profiling' => true, ], 'multisite' => $config ]; diff --git a/httpdocs/media/uploads/.gitignore b/httpdocs/media/uploads/.gitignore new file mode 100644 index 0000000000..612d950f34 --- /dev/null +++ b/httpdocs/media/uploads/.gitignore @@ -0,0 +1,4 @@ +# Ignore all files +** +# Except this file +!.gitignore diff --git a/resources/lang/en/validation.php b/resources/lang/en/validation.php index 861fb8a9f5..2d899c92bb 100644 --- a/resources/lang/en/validation.php +++ b/resources/lang/en/validation.php @@ -1,4 +1,4 @@ - * @package Ushahidi\Application diff --git a/src/App/Formatter/JSON.php b/src/App/Formatter/JSON.php index b8c1cb8d67..73231af8fb 100644 --- a/src/App/Formatter/JSON.php +++ b/src/App/Formatter/JSON.php @@ -11,7 +11,6 @@ namespace Ushahidi\App\Formatter; -use Kohana; use Ushahidi\Core\Tool\Formatter; use Ushahidi\Core\Tool\OutputFormatter; use Ushahidi\Core\Exception\FormatterException; @@ -21,8 +20,7 @@ class JSON implements Formatter, OutputFormatter protected function getOptions() { // Are we in development environment? - $dev_env = Kohana::$environment === Kohana::DEVELOPMENT; - return $dev_env ? JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES : null; + return env('APP_DEBUG', false) ? JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES : null; } // Formatter diff --git a/src/App/Formatter/Media.php b/src/App/Formatter/Media.php index 75e4411193..b2ff32264f 100644 --- a/src/App/Formatter/Media.php +++ b/src/App/Formatter/Media.php @@ -11,7 +11,6 @@ namespace Ushahidi\App\Formatter; -use Kohana; use Ushahidi\Core\Entity; use Ushahidi\Core\Traits\FormatterAuthorizerMetadata; @@ -21,12 +20,6 @@ class Media extends API protected function addMetadata(array $data, Entity $media) { - // Set image dimensions from the config file - $medium_width = Kohana::$config->load('media.image_medium_width'); - $medium_height = Kohana::$config->load('media.image_medium_height'); - $thumbnail_width = Kohana::$config->load('media.image_thumbnail_width'); - $thumbnail_height = Kohana::$config->load('media.image_thumbnail_height'); - return $data + [ // Add additional URLs and sizes // 'medium_file_url' => $this->resizedUrl($medium_width, $medium_height, $media->o_filename), @@ -60,53 +53,16 @@ protected function getFieldName($field) protected function formatOFilename($value) { - if ($cdnBaseUrl = Kohana::$config->load('cdn.baseurl')) { - //removes path from image file name, encodes the filename, and joins the path and filename together - $url_path = explode("/", $value); - $filename = rawurlencode(array_pop($url_path)); - array_push($url_path, $filename); - return $cdnBaseUrl . implode("/", $url_path); + // Removes path from image file name, encodes the filename, and joins the path and filename together + $url_path = explode("/", $value); + $filename = rawurlencode(array_pop($url_path)); + array_push($url_path, $filename); + $path = implode("/", $url_path); + + if ($cdnBaseUrl = config('cdn.baseurl')) { + return $cdnBaseUrl . $path; } else { - // URL::site or Media::uri already encodes the path properly, skip the path wrangling seen above - return \URL::site(\Media::uri($this->getRelativePath() . $value), \Request::current()); + return url(config('cdn.local.media_upload_dir') . '/' . $path); // @todo load from config } } - - private function getRelativePath() - { - return str_replace( - Kohana::$config->load('imagefly.source_dir'), - '', - Kohana::$config->load('media.media_upload_dir') - ); - } - - /** - * Return URL for accessing the resized image it. - * - * @param integer $width The width of the image - * @param integer $height The height of the image - * @param string $filename The file name of the image - * @return string URL to the resized image - */ - private function resizedUrl($width, $height, $filename) - { - - // Format demensions appropriately depending on the value of the height - if ($height != null) { - // Image height has been set - $dimension = sprintf('w%s-h%s', $width, $height); - } else { - // No image height set. - $dimension = sprintf('w%s', $width); - } - - return \URL::site( - \Route::get('imagefly')->uri(array( - 'params' => $dimension, - 'imagepath' => $this->getRelativePath() . $filename, - )), - \Request::current() - ); - } } diff --git a/src/App/Init.php b/src/App/Init.php index e4684d6365..e6e25825e7 100644 --- a/src/App/Init.php +++ b/src/App/Init.php @@ -559,7 +559,7 @@ ]; $di->setter[Ushahidi\App\Validator\Media\Create::class] = [ 'setMaxBytes' => $di->lazy(function () { - return \Kohana::$config->load('media.max_upload_bytes'); + return config('media.max_upload_bytes'); }), ]; $di->setter[Ushahidi\App\Validator\CSV\Create::class] = [ @@ -661,3 +661,76 @@ $di->setter[Ushahidi\App\Repository\Post\LockRepository::class]['setEvent'] = 'LockBroken'; $di->setter[Ushahidi\App\Repository\Post\LockRepository::class]['setListener'] = $di->lazyNew(Ushahidi\App\Listener\Lock::class); + +// Set up config bindings + +// Site config +$di->set('site.config', function () use ($di) { + return $di->get('repository.config')->get('site')->asArray(); +}); + +// Feature config +$di->set('features', function () use ($di) { + return $di->get('repository.config')->get('features')->asArray(); +}); + +// @todo add some kind of FeatureManager that owns all these checkes +// $features->isEnabled('roles') +// $features->getQuota('admins'); +// Roles config settings +$di->set('roles.enabled', function () use ($di) { + $config = $di->get('features'); + + return $config['roles']['enabled']; +}); + +// Feature config +$di->set('features.limits', function () use ($di) { + $config = $di->get('features'); + + return $config['limits']; +}); + +// Webhooks config settings +$di->set('webhooks.enabled', function () use ($di) { + $config = $di->get('features'); + + return $config['webhooks']['enabled']; +}); + +// Post Locking config settings +$di->set('post-locking.enabled', function () use ($di) { + $config = $di->get('features'); + + return $config['post-locking']['enabled']; +}); + +// Redis config settings +$di->set('redis.enabled', function () use ($di) { + $config = $di->get('features'); + + return $config['redis']['enabled']; +}); + +// Data import config settings +$di->set('data-import.enabled', function () use ($di) { + $config = $di->get('features'); + + return $config['data-import']['enabled']; +}); + +// Dataprovider feature config +$di->set('features.data-providers', function () use ($di) { + $config = $di->get('features'); + + return array_filter($config['data-providers']); +}); + +// Private deployment config settings +// @todo move to repo +$di->set('site.private', function () use ($di) { + $site = $di->get('site.config'); + $features = $di->get('features'); + return $site['private'] + and $features['private']['enabled']; +}); diff --git a/src/App/Listener/IntercomAdminListener.php b/src/App/Listener/IntercomAdminListener.php index d8ae90ac63..fc65e89c9a 100644 --- a/src/App/Listener/IntercomAdminListener.php +++ b/src/App/Listener/IntercomAdminListener.php @@ -54,8 +54,7 @@ public function handle(EventInterface $event, $user = null) $client->users->update($intercom_user); } catch (ClientException $e) { - // $message = $e->getMessage(); - // Kohana::$log->add(Log::ERROR, print_r($message,true)); + \Log::info($e->getMessage()); } } } diff --git a/src/App/Listener/IntercomCompanyListener.php b/src/App/Listener/IntercomCompanyListener.php index 4dc707827b..4f9d3d0fd1 100644 --- a/src/App/Listener/IntercomCompanyListener.php +++ b/src/App/Listener/IntercomCompanyListener.php @@ -39,7 +39,7 @@ public function handle(EventInterface $event, $data = null) // Update company $client->companies->create($company); } catch (ClientException $e) { - // Kohana::$log->add(Log::ERROR, print_r($e,true)); + \Log::info($e->getMessage()); } } } diff --git a/src/App/Multisite.php b/src/App/Multisite.php index 5d5dbb25ac..7db3c5f824 100644 --- a/src/App/Multisite.php +++ b/src/App/Multisite.php @@ -29,7 +29,8 @@ protected function parseHost($host) { if (!$this->domain && !$this->subdomain) { // Load the default domain - $domain = Kohana::$config->load('multisite.domain'); + // @todo stop call config directly + $domain = config('multisite.domain'); // If no host passed in, check the for HOST in environment if (!$host) { @@ -79,7 +80,8 @@ public function getDbConfig($host = null) } // Set new database config - $config = Repository\OhanzeeRepository::getDefaultConfig(); + // @todo stop call config directly + $config = config('ohanzee-db.default'); $config['connection'] = [ 'hostname' => $deployment['db_host'], diff --git a/src/App/Repository/Config/site.php b/src/App/Repository/Config/site.php index 1647d0587c..c2f0537a92 100644 --- a/src/App/Repository/Config/site.php +++ b/src/App/Repository/Config/site.php @@ -1,7 +1,7 @@ * @package Ushahidi\Application\Config diff --git a/src/App/Repository/Form/AttributeRepository.php b/src/App/Repository/Form/AttributeRepository.php index b0e9d5ce01..6f7805119f 100644 --- a/src/App/Repository/Form/AttributeRepository.php +++ b/src/App/Repository/Form/AttributeRepository.php @@ -112,7 +112,7 @@ public function create(Entity $entity) $uuid = Uuid::uuid4(); $record['key'] = $uuid->toString(); } catch (UnsatisfiedDependencyException $e) { - \Kohana::$log->add(Log::ERROR, $e->getMessage()); + Log::error($e->getMessage()); } return $this->executeInsertAttribute($this->removeNullValues($record)); } @@ -132,7 +132,7 @@ public function setSearchParams(SearchData $search) if (!empty($sorting['orderby'])) { $this->search_query->order_by( $this->getTable() . '.' . $sorting['orderby'], - \Arr::get($sorting, 'order') + isset($sorting['order']) ? $sorting['order'] : null ); } diff --git a/src/App/Repository/Form/StageRepository.php b/src/App/Repository/Form/StageRepository.php index b386ed2d00..4514ddd069 100644 --- a/src/App/Repository/Form/StageRepository.php +++ b/src/App/Repository/Form/StageRepository.php @@ -111,7 +111,7 @@ public function setSearchParams(SearchData $search) if (!empty($sorting['orderby'])) { $this->search_query->order_by( $this->getTable() . '.' . $sorting['orderby'], - \Arr::get($sorting, 'order') + isset($sorting['order']) ? $sorting['order'] : null ); } diff --git a/src/App/Repository/OhanzeeRepository.php b/src/App/Repository/OhanzeeRepository.php index 244fb6d82a..4b4919195c 100644 --- a/src/App/Repository/OhanzeeRepository.php +++ b/src/App/Repository/OhanzeeRepository.php @@ -102,7 +102,7 @@ public function setSearchParams(SearchData $search) if (!empty($sorting['orderby'])) { $this->search_query->order_by( $this->getTable() . '.' . $sorting['orderby'], - \Arr::get($sorting, 'order') + isset($sorting['order']) ? $sorting['order'] : null ); } diff --git a/src/App/Repository/SetRepository.php b/src/App/Repository/SetRepository.php index b1d3a0d54c..4eeb759530 100644 --- a/src/App/Repository/SetRepository.php +++ b/src/App/Repository/SetRepository.php @@ -144,7 +144,7 @@ public function setSearchParams(SearchData $search) if (!empty($sorting['orderby'])) { $this->search_query->order_by( $this->getTable() . '.' . $sorting['orderby'], - \Arr::get($sorting, 'order') + isset($sorting['order']) ? $sorting['order'] : null ); } diff --git a/src/Console/Command/Notification.php b/src/Console/Command/Notification.php index c9d9f7d35a..a252d56f8a 100644 --- a/src/Console/Command/Notification.php +++ b/src/Console/Command/Notification.php @@ -113,10 +113,10 @@ private function generateMessages($notification) } $subs = [ - ':sitename' => $site_name, - ':title' => $post->title, - ':content' => $post->content, - ':url' => $client_url . '/posts/' . $post->id + 'sitename' => $site_name, + 'title' => $post->title, + 'content' => $post->content, + 'url' => $client_url . '/posts/' . $post->id ]; $messageType = $this->mapContactToMessageType($contact->type); @@ -125,16 +125,8 @@ private function generateMessages($notification) $state = [ 'contact_id' => $contact->id, 'notification_post_id' => $post->id, - 'title' => strtr(Kohana::message( - 'notifications', - $messageType . '.title', - "New post: :title" - ), $subs), - 'message' => strtr(Kohana::message( - 'notifications', - $messageType . '.message', - "New post: :title" - ), $subs), + 'title' => trans('notifications.' . $messageType . '.title', $subs), + 'message' => trans('notifications.' . $messageType . '.message', $subs), 'type' => $messageType, 'data_source' => $data_source, ]; diff --git a/application/media/images/smssync.png b/tests/datasets/ushahidi/smssync.png similarity index 100% rename from application/media/images/smssync.png rename to tests/datasets/ushahidi/smssync.png diff --git a/application/media/test.geojson b/tests/datasets/ushahidi/test.geojson similarity index 100% rename from application/media/test.geojson rename to tests/datasets/ushahidi/test.geojson diff --git a/tests/integration/bootstrap/PHPUnitFixtureContext.php b/tests/integration/bootstrap/PHPUnitFixtureContext.php index 988c1378f3..e6ad1c0571 100644 --- a/tests/integration/bootstrap/PHPUnitFixtureContext.php +++ b/tests/integration/bootstrap/PHPUnitFixtureContext.php @@ -138,7 +138,7 @@ public function disableDataImport() public function getConnection() { // Get the unittesting db connection - $config = \Kohana::$config->load('database.'.$this->database_connection); + $config = config('ohanzee-db.'.$this->database_connection); if ($config['type'] !== 'pdo') { // Replace MySQLi with MySQL since MySQLi isn't valid for a DSN diff --git a/tests/integration/bootstrap/RestContext.php b/tests/integration/bootstrap/RestContext.php index 6753a0974e..367d8ed817 100644 --- a/tests/integration/bootstrap/RestContext.php +++ b/tests/integration/bootstrap/RestContext.php @@ -396,7 +396,7 @@ public function theResponseHasAProperty($propertyName) $data = json_decode($this->response->getBody(true), true); $this->theResponseIsJson(); - if (\Arr::path($data, $propertyName) === null) { + if (array_get($data, $propertyName) === null) { throw new \Exception("Property '".$propertyName."' is not set!\n"); } } @@ -411,7 +411,7 @@ public function theResponseDoesNotHaveAProperty($propertyName) $this->theResponseIsJson(); - if (\Arr::path($data, $propertyName) !== null) { + if (array_get($data, $propertyName) !== null) { throw new \Exception("Property '".$propertyName."' is set but should not be!\n"); } } @@ -424,7 +424,7 @@ public function thePropertyEquals($propertyName, $propertyValue) $data = json_decode($this->response->getBody(true), true); $this->theResponseIsJson(); - $actualPropertyValue = \Arr::path($data, $propertyName); + $actualPropertyValue = array_get($data, $propertyName); if ($actualPropertyValue === null) { throw new \Exception("Property '".$propertyName."' is not set!\n"); @@ -448,7 +448,7 @@ public function thePropertyIsTrue($propertyName) $this->theResponseIsJson(); - $actualPropertyValue = \Arr::path($data, $propertyName); + $actualPropertyValue = array_get($data, $propertyName); if ($actualPropertyValue === null) { throw new \Exception("Property '".$propertyName."' is not set!\n"); @@ -467,7 +467,7 @@ public function thePropertyIsFalse($propertyName) $this->theResponseIsJson(); - $actualPropertyValue = \Arr::path($data, $propertyName); + $actualPropertyValue = array_get($data, $propertyName); if ($actualPropertyValue === null) { throw new \Exception("Property '".$propertyName."' is not set!\n"); @@ -487,7 +487,7 @@ public function thePropertyContains($propertyName, $propertyContainsValue) $this->theResponseIsJson(); - $actualPropertyValue = \Arr::path($data, $propertyName); + $actualPropertyValue = array_get($data, $propertyName); if ($actualPropertyValue === null) { throw new Exception("Property '".$propertyName."' is not set!\n"); @@ -520,7 +520,7 @@ public function thePropertyDoesNotContains($propertyName, $propertyContainsValue $this->theResponseIsJson(); - $actualPropertyValue = \Arr::path($data, $propertyName); + $actualPropertyValue = array_get($data, $propertyName); if ($actualPropertyValue === null) { throw new Exception("Property '".$propertyName."' is not set!\n"); @@ -553,7 +553,7 @@ public function thePropertyCountIs($propertyName, $propertyCountValue) $this->theResponseIsJson(); - $actualPropertyValue = \Arr::path($data, $propertyName); + $actualPropertyValue = array_get($data, $propertyName); if ($actualPropertyValue === null) { throw new \Exception("Property '".$propertyName."' is not set!\n"); @@ -578,7 +578,7 @@ public function theTypeOfThePropertyIs($propertyName, $typeString) $this->theResponseIsJson(); - $actualPropertyValue = \Arr::path($data, $propertyName); + $actualPropertyValue = array_get($data, $propertyName); if ($actualPropertyValue === null) { throw new \Exception("Property '".$propertyName."' is not set!\n"); @@ -607,7 +607,7 @@ public function thePropertyIsEmpty($propertyName) $this->theResponseIsJson(); - $actualPropertyValue = \Arr::path($data, $propertyName); + $actualPropertyValue = array_get($data, $propertyName); if (!empty($actualPropertyValue)) { throw new \Exception("Property '{$propertyName}' is not empty!\n"); @@ -695,7 +695,7 @@ private function preparePostFileData($postFiles) */ private function prefixAppPath(&$item) { - $item = DOCROOT.'/../'.$item; + $item = base_path($item); } /**