Skip to content

Commit d412da3

Browse files
committed
Revert "Move mapping manipulation to a seperate trait."
This reverts commit 0a212b5. Let this be a lesson to you all, don't drink and code. Also, I am working on some integration tests, which will help skip us from hitting this issue again. Sorry, I am bad people.
1 parent 0a212b5 commit d412da3

File tree

2 files changed

+89
-94
lines changed

2 files changed

+89
-94
lines changed

src/ElasticquentMapping.php

Lines changed: 0 additions & 93 deletions
This file was deleted.

src/ElasticquentTrait.php

Lines changed: 89 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
*/
1313
trait ElasticquentTrait
1414
{
15-
use ElasticquentClientTrait, ElasticquentMapping, EloquentMethods;
15+
use ElasticquentClientTrait, EloquentMethods;
1616

1717
/**
1818
* Uses Timestamps In Index
@@ -430,6 +430,94 @@ private function buildFieldsParameter($getSourceIfPossible, $getTimestampIfPossi
430430
return $fieldsParam;
431431
}
432432

433+
/**
434+
* Mapping Exists
435+
*
436+
* @return bool
437+
*/
438+
public static function mappingExists()
439+
{
440+
$instance = new static;
441+
442+
$mapping = $instance->getMapping();
443+
444+
return (empty($mapping)) ? false : true;
445+
}
446+
447+
/**
448+
* Get Mapping
449+
*
450+
* @return void
451+
*/
452+
public static function getMapping()
453+
{
454+
$instance = new static;
455+
456+
$params = $instance->getBasicEsParams();
457+
458+
return $instance->getElasticSearchClient()->indices()->getMapping($params);
459+
}
460+
461+
/**
462+
* Put Mapping.
463+
*
464+
* @param bool $ignoreConflicts
465+
*
466+
* @return array
467+
*/
468+
public static function putMapping($ignoreConflicts = false)
469+
{
470+
$instance = new static;
471+
472+
$mapping = $instance->getBasicEsParams();
473+
474+
$params = array(
475+
'_source' => array('enabled' => true),
476+
'properties' => $instance->getMappingProperties(),
477+
);
478+
479+
$mapping['body'][$instance->getTypeName()] = $params;
480+
481+
return $instance->getElasticSearchClient()->indices()->putMapping($mapping);
482+
}
483+
484+
/**
485+
* Delete Mapping
486+
*
487+
* @return array
488+
*/
489+
public static function deleteMapping()
490+
{
491+
$instance = new static;
492+
493+
$params = $instance->getBasicEsParams();
494+
495+
return $instance->getElasticSearchClient()->indices()->deleteMapping($params);
496+
}
497+
498+
/**
499+
* Rebuild Mapping
500+
*
501+
* This will delete and then re-add
502+
* the mapping for this model.
503+
*
504+
* @return array
505+
*/
506+
public static function rebuildMapping()
507+
{
508+
$instance = new static;
509+
510+
// If the mapping exists, let's delete it.
511+
if ($instance->mappingExists()) {
512+
$instance->deleteMapping();
513+
}
514+
515+
// Don't need ignore conflicts because if we
516+
// just removed the mapping there shouldn't
517+
// be any conflicts.
518+
return $instance->putMapping();
519+
}
520+
433521
/**
434522
* Create Index
435523
*

0 commit comments

Comments
 (0)