Skip to content

Commit

Permalink
Fixes for setTags() and empty tags
Browse files Browse the repository at this point in the history
FIX: setTags() did not call loadTags(). Furtheron, neededSave() would
re-save even though no tags had changed, or not save when empty
setTags(array()) was called.

FIX: in for loop while saving in afterSave(), when empty tag was found,
continue instead of aborting.

CHG: remove empty tags before handling
  • Loading branch information
marcovtwout authored and samdark committed Feb 18, 2015
1 parent b371354 commit 7394c33
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions ETaggableBehavior.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ private function getModelTableFkName() {
* @return void
*/
public function setTags($tags) {
$this->loadTags();

$tags = $this->toTagsArray($tags);
$this->tags = array_unique($tags);

Expand Down Expand Up @@ -283,6 +285,7 @@ protected function toTagsArray($tags) {
}

array_walk($tags, array($this, 'trim'));
$tags = array_filter($tags, 'strlen');
return $tags;
}
/**
Expand Down Expand Up @@ -355,7 +358,7 @@ public function afterSave($event) {
// add new tag bindings and tags if there are any
if(!empty($this->tags)){
foreach($this->tags as $tag){
if(empty($tag)) return;
if(empty($tag)) continue;

// try to get existing tag
$findCriteria = new CDbCriteria(array(
Expand Down Expand Up @@ -699,4 +702,4 @@ protected function updateCount($count) {
)->execute();
}
}
}
}

0 comments on commit 7394c33

Please sign in to comment.