],
"require": {
"php": ">=7.1.3",
+ "ext-dom": "*",
+ "ext-libxml": "*",
"backpack/crud": "^3.6",
"backpack/backupmanager": "^1.4",
"backpack/logmanager": "^2.3",
"barryvdh/laravel-debugbar": "^3.2",
"league/commonmark-ext-autolink": "^1.0",
"cviebrock/laravel-elasticsearch": "^3.6"
+
},
"require-dev": {
"filp/whoops": "^2.3",
namespace Cubist\Backpack\app\Console\Commands;
+use Cubist\Backpack\app\Magic\Menu\Menu;
+use Cubist\Backpack\app\Magic\Menu\PageItem;
+use Cubist\Backpack\app\Magic\Menu\VirtualItem;
+use Cubist\Backpack\app\Template\Navigation;
+use Cubist\Backpack\app\Template\Redirection;
+use Cviebrock\LaravelElasticsearch\Facade;
+use DOMDocument;
use Illuminate\Console\Command;
public function handle()
{
+ Facade::
+ /** @var Cubist\Backpack\app\Magic\Menu\Item[] $pages */
+ $pages = Menu::getNavigation()->findAll();
+ foreach ($pages as $page) {
+ // Skip nav items
+ if ($page instanceof VirtualItem) {
+ continue;
+ }
+ // Skip redirection & navigation pages
+ if ($page instanceof PageItem) {
+ /** @var PageItem $template */
+ $template = $page->getPage()->getUsedTemplate();
+ if ($template instanceof Redirection || $template instanceof Navigation) {
+ continue;
+ }
+ }
+
+ libxml_use_internal_errors(true);
+ $doc = new DOMDocument();
+ $doc->loadHTMLFile($page->getHref());
+
+ $title = $doc->getElementsByTagName('title');
+ $body = $doc->getElementsByTagName('body');
+
+ $data = [
+ 'body' => [
+ 'title' => $title->item(0)->nodeValue,
+ 'body' => $body->item(0)->nodeValue,
+ ],
+ 'index' => env('ELASTICSEARCH_INDEX_NAME', 'cubist_elastic_default'),
+ 'type' => 'cmspage',
+ 'id' => $page->getHref(),
+ ];
+
+ print_r($data);
+
+ Elasticsearch::index($data);
+ }
}
}
protected $_cast = false;
protected $_translatable = false;
- protected $_elastic = false;
- protected $_elasticType = 'string';
- protected $_elasticAnalyser = 'standard';
-
/**
* @var CubistMagicAbstractModel
*/
return ['type' => $this->_adminType, 'view_namespace' => $this->_viewNamespace, 'column' => false, 'form' => 'both', 'rules' => '',
'fillable' => true, 'guarded' => false, 'hidden' => false, 'translatable' => $this->_translatable,
'column_type' => $this->_columnType, 'default' => '', 'cast' => $this->_cast, 'column_view_namespace' => $this->_columnViewNamespace, 'searchLogic' => $this->_searchLogic,
- 'elastic' => $this->_elastic, 'elastic_type' => $this->_elasticType, 'elastic_analyser' => $this->_elasticAnalyser,
'allow_null' => true,
'fake' => false, 'store_in' => 'extras', 'attributes' => []];
}
}
}
- public function getElasticMapping()
- {
- if (!$this->getAttribute('elastic', false)) {
- return [];
- }
- return [$this->getAttribute('name') =>
- [
- 'type' => $this->getAttribute('elastic_type'),
- 'analyser' => $this->getAttribute('elastic_analyser')
- ]
- ];
- }
-
/**
* @return null|string
*/
return $this->findOneBy('href', $href);
}
+ public function findAll()
+ {
+ $res = [$this];
+
+ foreach ($this->getChildren() as $child) {
+ $res = array_merge($res, $child->findAll());
+ }
+
+ return $res;
+ }
+
public function findAllBy($param, $search)
{
$res = [];
use Spatie\MediaLibrary\HasMedia\HasMediaTrait;
use Spatie\MediaLibrary\Models\Media;
use Venturecraft\Revisionable\RevisionableTrait;
-use Elasticquent\ElasticquentTrait;
class CubistMagicAbstractModel extends Model implements HasMedia
{
use BunchOfFields {
addField as protected bunchAddField;
}
- use ElasticquentTrait;
protected static $_doctrineTypesMapping = ['int' => 'integer'];
*/
protected $varSetBeforeOperations = [];
- /**
- * @var array
- */
- protected $mappingProperties = [];
-
public static function boot()
{
parent::boot();
}
-
public function __construct(array $attributes = [])
{
$this->setFields();