diff --git a/composer.json b/composer.json index a905b3b..16365c5 100644 --- a/composer.json +++ b/composer.json @@ -10,9 +10,9 @@ ], "require": { "php": ">=5.4.0", - "illuminate/support": "~4.2", - "illuminate/database": "~4.2", - "illuminate/console": "~4.2", + "illuminate/support": "~5.0", + "illuminate/database": "~5.0", + "illuminate/console": "~5.0", "doctrine/dbal": "~2.3", "elasticsearch/elasticsearch": "~1.0", "nikic/php-parser": "*" diff --git a/src/Iverberk/Larasearch/Commands/PathsCommand.php b/src/Iverberk/Larasearch/Commands/PathsCommand.php index 904293f..9f05815 100644 --- a/src/Iverberk/Larasearch/Commands/PathsCommand.php +++ b/src/Iverberk/Larasearch/Commands/PathsCommand.php @@ -310,13 +310,14 @@ private function writeConfig() { if ($this->option('write-config')) { - $configDir = app_path() . '/config/packages/iverberk/larasearch'; + $configFile = base_path() . '/config/larasearch.php'; + $configDir = base_path() . '/config'; - if (!File::exists($configDir)) + if (!File::exists($configFile)) { if ($this->confirm('It appears that you have not yet published the larasearch config. Would you like to do this now?', false)) { - $this->call('config:publish', ['package' => 'iverberk/larasearch']); + $this->call('vendor:publish', ['package' => 'iverberk/larasearch']); } else { diff --git a/src/Iverberk/Larasearch/Exceptions/ImportException.php b/src/Iverberk/Larasearch/Exceptions/ImportException.php index a351f6b..965b628 100644 --- a/src/Iverberk/Larasearch/Exceptions/ImportException.php +++ b/src/Iverberk/Larasearch/Exceptions/ImportException.php @@ -7,6 +7,7 @@ class ImportException extends Exception { // Redefine the exception so message isn't optional public function __construct($message, $code = 0, $errorItems = []) { + var_dump($errorItems); // make sure everything is assigned properly parent::__construct($message, $code); } diff --git a/src/Iverberk/Larasearch/Index.php b/src/Iverberk/Larasearch/Index.php index d104b4b..118784a 100644 --- a/src/Iverberk/Larasearch/Index.php +++ b/src/Iverberk/Larasearch/Index.php @@ -120,7 +120,7 @@ public function import(Model $model, $relations = [], $batchSize = 750, Callable */ public function setName($name) { - $index_prefix = Config::get('larasearch::elasticsearch.index_prefix', ''); + $index_prefix = Config::get('larasearch.elasticsearch.index_prefix', ''); if ($index_prefix && ! Str::startsWith($name, $index_prefix)) $name = $index_prefix . $name; $this->name = $name; @@ -200,7 +200,7 @@ public function exists() */ public function aliasExists($alias) { - $index_prefix = Config::get('larasearch::elasticsearch.index_prefix', ''); + $index_prefix = Config::get('larasearch.elasticsearch.index_prefix', ''); if ($index_prefix && ! Str::startsWith($alias, $index_prefix)) $alias = $index_prefix . $alias; return self::getClient()->indices()->existsAlias(['name' => $alias]); @@ -311,7 +311,7 @@ public function bulk($records) */ public static function clean($name) { - $index_prefix = Config::get('larasearch::elasticsearch.index_prefix', ''); + $index_prefix = Config::get('larasearch.elasticsearch.index_prefix', ''); if ($index_prefix && ! Str::startsWith($name, $index_prefix)) $name = $index_prefix . $name; $indices = self::getClient()->indices()->getAliases(); @@ -332,7 +332,7 @@ public static function clean($name) */ public static function getAlias($name) { - $index_prefix = Config::get('larasearch::elasticsearch.index_prefix', ''); + $index_prefix = Config::get('larasearch.elasticsearch.index_prefix', ''); if ($index_prefix && ! Str::startsWith($name, $index_prefix)) $name = $index_prefix . $name; return self::getClient()->indices()->getAlias(['name' => $name]); @@ -344,7 +344,7 @@ public static function getAlias($name) */ public static function updateAliases(array $actions) { - if (isset($actions['actions']) && ($index_prefix = Config::get('larasearch::elasticsearch.index_prefix', ''))) + if (isset($actions['actions']) && ($index_prefix = Config::get('larasearch.elasticsearch.index_prefix', ''))) { foreach ($actions['actions'] as &$action) { @@ -365,7 +365,7 @@ public static function updateAliases(array $actions) */ public static function refresh($index) { - $index_prefix = Config::get('larasearch::elasticsearch.index_prefix', ''); + $index_prefix = Config::get('larasearch.elasticsearch.index_prefix', ''); if ($index_prefix && ! Str::startsWith($index, $index_prefix)) $index = $index_prefix . $index; return self::getClient()->indices()->refresh(['index' => $index]); @@ -378,8 +378,8 @@ public static function refresh($index) */ private function getDefaultIndexParams() { - $analyzers = Config::get('larasearch::elasticsearch.analyzers'); - $params = Config::get('larasearch::elasticsearch.defaults.index'); + $analyzers = Config::get('larasearch.elasticsearch.analyzers'); + $params = Config::get('larasearch.elasticsearch.defaults.index'); $mapping = []; $mapping_options = array_combine( diff --git a/src/Iverberk/Larasearch/LarasearchServiceProvider.php b/src/Iverberk/Larasearch/LarasearchServiceProvider.php index 8cf82f3..704f538 100644 --- a/src/Iverberk/Larasearch/LarasearchServiceProvider.php +++ b/src/Iverberk/Larasearch/LarasearchServiceProvider.php @@ -7,6 +7,7 @@ use Iverberk\Larasearch\Response\Result; use Monolog\Handler\NullHandler; use Monolog\Logger; +use ReflectionClass; class LarasearchServiceProvider extends ServiceProvider { @@ -19,7 +20,9 @@ class LarasearchServiceProvider extends ServiceProvider { public function boot() { - $this->package('iverberk/larasearch'); + $this->publishes([ + $this->guessPackagePath() . '/config/config.php' => config_path('larasearch.php'), + ]); $this->bootContainerBindings(); } @@ -57,7 +60,7 @@ protected function bindElasticsearch() { $this->app->singleton('Elasticsearch', function ($app) { - return new Client($app->make('config')->get('larasearch::elasticsearch.params')); + return new Client($app->make('config')->get('larasearch.elasticsearch.params')); }); } @@ -148,4 +151,15 @@ public function provides() return array(); } + /** + * Guess real path of the package. + * + * @return string + */ + public function guessPackagePath() + { + $path = (new ReflectionClass($this))->getFileName(); + + return realpath(dirname($path).'/../..'); + } } diff --git a/src/Iverberk/Larasearch/Observer.php b/src/Iverberk/Larasearch/Observer.php index 2c8e96b..3bbfb04 100644 --- a/src/Iverberk/Larasearch/Observer.php +++ b/src/Iverberk/Larasearch/Observer.php @@ -45,7 +45,7 @@ private function findAffectedModels(Model $model, $excludeCurrent = false) // Temporary array to store affected models $affectedModels = []; - $paths = Config::get('larasearch::reversedPaths.' . get_class($model), []); + $paths = Config::get('larasearch.reversedPaths.' . get_class($model), []); foreach ((array)$paths as $path) { diff --git a/src/Iverberk/Larasearch/Proxy.php b/src/Iverberk/Larasearch/Proxy.php index b84fb9f..5a8cd70 100644 --- a/src/Iverberk/Larasearch/Proxy.php +++ b/src/Iverberk/Larasearch/Proxy.php @@ -125,7 +125,7 @@ public function reindex($relations = false, $batchSize = 750, $mapping = [], Cal $name = $this->config['index']->getName(); $newName = $name . '_' . date("YmdHis"); - $relations = $relations ? Config::get('larasearch::paths.' . get_class($model)) : []; + $relations = $relations ? Config::get('larasearch.paths.' . get_class($model)) : []; Index::clean($name); diff --git a/src/Iverberk/Larasearch/Response/Result.php b/src/Iverberk/Larasearch/Response/Result.php index 30874c3..299b5bb 100644 --- a/src/Iverberk/Larasearch/Response/Result.php +++ b/src/Iverberk/Larasearch/Response/Result.php @@ -1,8 +1,8 @@ load($relations)->toArray();