setData Function for deleting article settings (sponsor, copyrightHolder) does not work

I try to delete existing article settings like sponsor or CopyrightHolder from table article_settings. However, this does not work:

$article->setData('sponsor',null, null);

Or

$article->setSponsor(null,null)

Any idea, what’s the right way to delete such settings? I am using OJS 2.4.8.1.

Hi @aguen,

Are you using the DAO to update the database record after setting the field? Also, there’s $article->setSponsor(), which is preferable to using setData.

Regards,
Alec Smecher
Public Knowledge Project Team

1 Like

Hi Alec,

Thank you for your reply! I did not realize that setSponsor() or setData() does not actually execute the SQL but only configures/sets it. Now I see that $articleDao->updateSetting() is required to execute the update for individual settings or $articleDao->updateArticle() to execute all settings. Something like the code below did the job (= deleting all existing sponsors and inserting a new one).

Thanks,
Armin

$existingSponsors = $article->getSponsor(null);
if($existingSponsors) {
	foreach (array_keys($existingSponsors) as $locale) {
        $article->setSponsor(null,$locale);
        $articleDao->updateSetting($article->getId(),'sponsor',array($locale=>null),'string',true );
	}
}
$newSponsor = 'The new sponsor';
$locale = 'en_US';
$article->setSponsor($newSponsor,$locale);
$articleDao->updateSetting($article->getId(),'sponsor',array($locale=>$newSponsor),'string',true );
1 Like