Commit 6094465d authored by Francesco Iannuzzelli's avatar Francesco Iannuzzelli

Fix keyword removal

parent 61d5adb5
......@@ -616,6 +616,19 @@ class Keyword
return $rows;
}
public function UseArticlesByUser( $id_keyword,$id_user)
{
$db =& Db::globaldb();
$rows = array();
$sqlstr = "SELECT a.id_article,a.headline
FROM keywords_use ku
INNER JOIN articles a ON ku.id=a.id_article
WHERE ku.id_keyword='$id_keyword' AND a.approved=1 AND a.id_user=$id_user AND a.published>0
ORDER BY a.published DESC";
$db->QueryExe($rows, $sqlstr);
return $rows;
}
public function UseArticlesPaged( &$rows,$id_keyword,$id_template,$id_topic,$id_subtopic=0)
{
if(is_null($id_template))
......
......@@ -35,27 +35,25 @@ $options = getopt("k:u:");
if(is_array($options) && isset($options['k']) && isset($options['u']) && $options['k']!="" && $options['u']>0)
{
$id_user = (int)$options['u'];
$decoded_keyword = strtolower(urldecode($options['k']));
include_once(SERVER_ROOT."/../classes/keyword.php");
$k = new Keyword();
$keyword = $k->KeywordCheck($options['k']);
if($id_user>0 && isset($keyword['id_keyword'])) {
$articles = array();
$id_keyword = $k->KeywordGetId($decoded_keyword);
if($id_user>0 && $id_keyword>0) {
// find all articles associated to this keyword
$num_articles = $k->UseArticlesPaged($articles,$keyword['id_keyword'],0,0);
if($num_articles>0) {
$articles = $k->UseArticlesByUser($id_keyword,$id_user);
if(count($articles)>0) {
include_once(SERVER_ROOT."/../classes/ontology.php");
$o = new Ontology;
foreach($articles as $article) {
$o->KeywordRemove($article['id_article'], $o->types['article'], $keyword['id_keyword']);
echo "Keyword {$options['k']} removed from article \"{$article['headline']}\"\n";
}
$articles_left = $num_articles - count($articles);
if($articles_left>0) {
echo "There are $articles_left articles left, please run it again\n";
$o->KeywordRemove($article['id_article'], $o->types['article'], $id_keyword);
echo "Keyword \"$decoded_keyword\" removed from article {$article['id_article']} \"{$article['headline']}\"\n";
}
} else {
echo "No articles with keyword $keyword by user $id_user\n";
echo "No articles with keyword \"$decoded_keyword\" by user $id_user\n";
}
} else {
echo "Keyword \"$decoded_keyword\" not found\n";
}
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment