Skip to content
Snippets Groups Projects

hotline: #143141 : album change codif

Compare and
3 files
+ 58
12
Preferences
Compare changes
Files
3
@@ -26,6 +26,7 @@ class Class_Migration_AlbumChangeCodif {
$_codif_name,
$_id_origin,
$_id_replace,
$_force_update,
$_map_attrib_class = [
'genre' => Class_CodifGenre::class,
'sections' => Class_CodifSection::class,
@@ -33,31 +34,29 @@ class Class_Migration_AlbumChangeCodif {
'matiere' => Class_CodifMatiere::class
];
public function __construct($cat_id, $codif_name, $id_origin, $id_replace) {
public function __construct($cat_id, $codif_name,
$id_origin, $id_replace, $force_update = false) {
$this->_cat_id = $cat_id;
$this->_codif_name = $codif_name;
$this->_id_origin = $id_origin;
$this->_id_replace = $id_replace;
$this->_force_update = $force_update;
}
public function run() : string {
try {
if (!$this->_cat_id
|| !$category = Class_AlbumCategorie::find($this->_cat_id))
if (!$category = $this->_getCategory())
return "Category can't be found with id: " . $this->_cat_id;
if (!$this->_codif_name
|| !isset($this->_map_attrib_class[$this->_codif_name]))
if (!$this->_isCodifNameValid())
return sprintf("Codif %s doesn't exist", $this->_codif_name);
$codif = $this->_map_attrib_class[$this->_codif_name];
if (!$this->_id_origin
|| $codif::find($this->_id_origin))
if (!$this->_isOriginCodifValid($codif))
return sprintf("%s with id: %s should not exists", $codif, $this->_id_origin);
if (!$this->_id_replace
|| !$codif::find($this->_id_replace))
if (!$this->_isReplaceCodifValid($codif))
return sprintf("%s can't be found with id: %s", $codif, $this->_id_replace);
$albums = Class_Album::findAllBy(['cat_id' => $category
@@ -97,4 +96,30 @@ class Class_Migration_AlbumChangeCodif {
return 0;
}
protected function _getCategory() {
if (!$this->_cat_id)
return null;
return Class_AlbumCategorie::find($this->_cat_id);
}
protected function _isCodifNameValid() : bool {
return $this->_codif_name && isset($this->_map_attrib_class[$this->_codif_name]);
}
protected function _isOriginCodifValid($codif): bool {
if (!$this->_id_origin)
return false;
return $this->_force_update || !$codif::find($this->_id_origin);
}
protected function _isReplaceCodifValid($codif) : bool {
return $this->_id_replace && $codif::find($this->_id_replace);
}
}