Index: trunk/kernel/include/language.php =================================================================== diff -u -r925 -r926 --- trunk/kernel/include/language.php (.../language.php) (revision 925) +++ trunk/kernel/include/language.php (.../language.php) (revision 926) @@ -399,6 +399,16 @@ function DeleteLanguage($id) { $l = $this->GetItem($id); + if($l->Get('PrimaryLang')==1) + { + // in case if primary language is deleted, + // set 1st available (min ID) from languages + // table. + $db =& GetADODBConnection(); + $sql = 'SELECT MIN(LanguageId) FROM '.$this->SourceTable.' WHERE LanguageId <> '.$l->UniqueId(); + $new_id=$db->GetOne($sql); + $db->Execute('UPDATE '.$this->SourceTable.' SET PrimaryLang = 1, Enabled = 1 WHERE LanguageId = '.$new_id); + } $l->Delete(); } @@ -417,26 +427,20 @@ $data = $rs->fields; $c = $this->AddItemFromArray($data); $c->Dirty(); + + if($c->Get('PrimaryLang') == 1) + { + $c->Set('Enabled',1); + $sql = 'UPDATE '.$this->SourceTable.' SET PrimaryLang = 0'; + $this->adodbConnection->Execute($sql); + } if($data["LanguageId"]>0) { - // m_dirtyFieldsMap is private property of class clsItemDB, - // it is highly unrecommended to use it here, use $c->Get - // instead. Needs refactoring - duplicate code. - if ($c->m_dirtyFieldsMap["PrimaryLang"] == 1) { - $sql = "UPDATE ".$this->SourceTable." SET PrimaryLang = 0"; - $this->adodbConnection->Execute($sql); - } - $c->Update(); } else { - if ($c->m_dirtyFieldsMap["PrimaryLang"] == 1) { - $sql = "UPDATE ".$this->SourceTable." SET PrimaryLang = 0"; - $this->adodbConnection->Execute($sql); - } - $oldid = $c->Get("LanguageId"); $c->UnsetIdField(); $c->Create();