{"id":1931,"date":"2014-12-31T08:55:32","date_gmt":"2014-12-31T14:55:32","guid":{"rendered":"http:\/\/www.mooreds.com\/wordpress\/?p=1931"},"modified":"2014-12-22T16:17:10","modified_gmt":"2014-12-22T22:17:10","slug":"dont-forget-to-deactivate-inactive-items-in-easyrec","status":"publish","type":"post","link":"https:\/\/www.mooreds.com\/wordpress\/archives\/1931","title":{"rendered":"Don&#8217;t forget to deactivate inactive items in easyrec"},"content":{"rendered":"<figure style=\"width: 150px\" class=\"wp-caption alignleft\"><img decoding=\"async\" class=\"alignleft\" title=\"Delete key by Ervins Strauhmanis\" src=\"http:\/\/www.mooreds.com\/wordpress\/wp-content\/uploads\/2014\/12\/10135243453_d66ac7be69_q_delete.jpg\" alt=\"delete photo\" width=\"150\" \/><figcaption class=\"wp-caption-text\"><small>Photo by <a href=\"http:\/\/www.flickr.com\/photos\/76523360@N03\/10135243453\" target=\"_blank\">Ervins Strauhmanis<\/a> <a title=\"Attribution License\" href=\"http:\/\/creativecommons.org\/licenses\/by\/2.0\/\" target=\"_blank\" rel=\"nofollow\"><img decoding=\"async\" src=\"http:\/\/www.mooreds.com\/wordpress\/wp-content\/plugins\/wp-inject\/images\/cc.png\" alt=\"\" \/><\/a><\/small><\/figcaption><\/figure>\n<p>I wrote before about <a href=\"\/wordpress\/archives\/988\">easyrec<\/a>, a recommendation system with an easy to integrate javascript API, but just recently realized that I was still showing inactive items as &#8216;recommended&#8217;.\u00a0 This is because I was marking items inactive in my database, but not in my easyrec system.<\/p>\n<p>Luckily, there&#8217;s an API call to <a href=\"http:\/\/easyrec.sourceforge.net\/wiki\/index.php\/REST_API_v0.98#set_item_active\">mark items inactive<\/a>.\u00a0 You could of course manually login and mark them as inactive, but using the API and a bit of SQL lets me run this check for all the items.\u00a0 Right now I&#8217;m just doing this manually, but will probably put it in a cron job to make sure all inactive items are marked so in easyrec.<\/p>\n<p>Here&#8217;s the SQL (escaped so it doesn&#8217;t wrap):<\/p>\n<blockquote><p><code>select concat('wget \"http:\/\/hostname\/api\/1.0\/json\/setitemactive?apikey=apikey&amp;tenantid=tenantid&amp;\\<br \/>\nactive=false&amp;itemtype=ITEM&amp;itemid=',id,'\"; sleep 5;')<br \/>\nfrom itemtable where enabled = 0;<\/code><\/p><\/blockquote>\n<p>I have an item table that looks like this:<\/p>\n<blockquote><p><code>CREATE TABLE `itemtable` (<br \/>\n`id` int(10) unsigned NOT NULL AUTO_INCREMENT,<br \/>\n...<br \/>\n`enabled` tinyint(1) NOT NULL DEFAULT '1',<br \/>\n...<br \/>\n<\/code><\/p><\/blockquote>\n<p>Where <code>enabled<\/code> is set to 0 for disabled items and 1 for enabled items. The <code>id<\/code> column is numeric and also happens to be the easyrec item id number, in a happy coincidence.<\/p>\n<p>The end output is a series of <code>wget<\/code> and <code>sleep<\/code> commands that I can run in the shell. I added in the sleep commands because I&#8217;m on the demo host of easyrec and didn&#8217;t want to overwhelm their server with updates.<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I wrote before about easyrec, a recommendation system with an easy to integrate javascript API, but just recently realized that I was still showing inactive items as &#8216;recommended&#8217;.\u00a0 This is [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[62,5,20],"tags":[],"class_list":["post-1931","post","type-post","status-publish","format-standard","hentry","category-apis","category-java","category-web-applications"],"_links":{"self":[{"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/posts\/1931","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/comments?post=1931"}],"version-history":[{"count":6,"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/posts\/1931\/revisions"}],"predecessor-version":[{"id":1938,"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/posts\/1931\/revisions\/1938"}],"wp:attachment":[{"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/media?parent=1931"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/categories?post=1931"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/tags?post=1931"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}