{"id":1767,"date":"2017-09-27T16:31:14","date_gmt":"2017-09-27T16:31:14","guid":{"rendered":"https:\/\/ibex.tech\/cloud\/?p=1767"},"modified":"2022-02-17T07:14:02","modified_gmt":"2022-02-17T07:14:02","slug":"universal-settings-table","status":"publish","type":"post","link":"https:\/\/ibex.tech\/cloud\/mysql\/examples-mysql\/universal-settings-table","title":{"rendered":"Universal Settings Table"},"content":{"rendered":"<h4>\nTable Design<br \/>\n<\/h4>\n<p>\nRecordId\n<\/p>\n<p style=\"margin-left: 40px;\">\nAuto Increment<br \/>\nint (unisigned)<br \/>\nPrimary Key\n<\/p>\n<p>\nSettingName\n<\/p>\n<p style=\"margin-left: 40px;\">\nvarchar\n<\/p>\n<p>\nSettingValue\n<\/p>\n<p style=\"margin-left: 40px;\">\ntext\n<\/p>\n<h4>\nIs A Setting Enabled?<br \/>\n<\/h4>\n<pre>\r\n<code>\r\n\t\/\/----- CHECK IF UPLOADS ARE ENABLED CURRENTLY -----\r\n\t$QueryString = @mysql_query(&quot;SELECT SettingValue FROM tblApiSettings WHERE SettingName = &#39;ArchiveDataUploadsEnabled&#39;&quot;);\r\n\t$result = @mysql_fetch_array($QueryString);\r\n\t$UploadsEnabled = $result['SettingValue'];\r\n\t$UploadsEnabled = filter_var($UploadsEnabled, FILTER_VALIDATE_BOOLEAN);\r\n\tif (!$UploadsEnabled)\r\n\t\tdie(&quot;Quitting - Uploads import is currently disabled&quot;);\r\n<\/code><\/pre>\n<h4>\nIs A Background Task Already Being Done (With timeout check)<br \/>\n<\/h4>\n<pre>\r\n<code>\r\n\t\/\/----- CHECK IF THIS TASK IS ALREADY RUNNING CURRENTLY -----\r\n\t\/\/(Started from an earlier CRON call)\r\n\t$QueryString = @mysql_query(&quot;SELECT SettingValue FROM tblApiSettings WHERE SettingName = &#39;ArchiveDataUploadsImportActive&#39;&quot;);\r\n\t$result = @mysql_fetch_array($QueryString);\r\n\t$ArchiveDataUploadsImportActive = $result['SettingValue'];\r\n\t\r\n\tif ($ArchiveDataUploadsImportActive != &quot;0&quot;)\r\n\t{\r\n\t\t$end = strtotime(date(&quot;Y-m-d H:i:s&quot;));\t\t\/\/Now\r\n\t\t$start = strtotime($ArchiveDataUploadsImportActive);\r\n\t\tif ($start &lt;= $end)\r\n\t\t{\r\n\t\t\t$no_of_minutes = ceil(abs($end - $start) \/ 60);   \/\/ceil rounds the amount of days up to the next full day. Use floor if you want to get the amount of full days between the two dates.\r\n\t\t\tif ($no_of_minutes &lt; 120)\t\t\t\/\/&lt;&lt;&lt;Timeout, if longer than this many minutes has passed ignore the setting as old task must have died for some reason without clearing this\r\n\t\t\t{\r\n\t\t\t\t\/\/----- UPLOADS IMPORT IS ALREADY ACTIVE -----\r\n\t\t\t\tdie(&quot;Quitting - Uploads import is already active (started: &quot; .$ArchiveDataUploadsImportActive . &quot;)&quot;);\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n<\/code><\/pre>\n<pre>\r\n<code>\r\n\t\/\/----- FLAG THAT WE ARE ACTIVE CARRYING OUT IMPORT -----\r\n\t\/\/(Stop other cron calls also doing this until we quit.  We use a timestamp to allow them to detect if something has gone wrong and too much time has passed)\r\n\t$TimeNow = date(&quot;Y-m-d H:i:s&quot;);\r\n\t$result = @mysql_query(&quot;UPDATE tblApiSettings SET\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tSettingValue = &#39;$TimeNow&#39;\r\n\t\t\t\t\t\t\t\t\t\t\t\t\tWHERE SettingName = &#39;ArchiveDataUploadsImportActive&#39;\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t&quot;);\r\n\r\n<\/code><\/pre>\n<pre>\r\n<code>\r\n\t\/\/----- FLAG THAT IMPORT IS COMPLETE -----\r\n\t\/\/(Remove block on other cron calls doing this task)\r\n\t$TimeNow = date(&quot;Y-m-d H:i:s&quot;);\r\n\t$result = @mysql_query(&quot;UPDATE tblApiSettings SET\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tSettingValue = &#39;0&#39;\r\n\t\t\t\t\t\t\t\t\t\t\t\t\tWHERE SettingName = &#39;ArchiveDataUploadsImportActive&#39;\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t&quot;);\r\n\r\n<\/code><\/pre>\n<p>\n&nbsp;\n<\/p>\n<p>\n&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Table Design RecordId Auto Increment int (unisigned) Primary Key SettingName varchar SettingValue text Is A Setting Enabled? \/\/&#8212;&#8211; CHECK IF UPLOADS ARE ENABLED CURRENTLY &#8212;&#8211; $QueryString = @mysql_query(&quot;SELECT SettingValue FROM tblApiSettings WHERE SettingName = &#39;ArchiveDataUploadsEnabled&#39;&quot;); $result = @mysql_fetch_array($QueryString); $UploadsEnabled = $result[&#8216;SettingValue&#8217;]; $UploadsEnabled = filter_var($UploadsEnabled, FILTER_VALIDATE_BOOLEAN); if (!$UploadsEnabled) die(&quot;Quitting &#8211; Uploads import is currently disabled&quot;); Is [&hellip;]<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[148],"tags":[],"class_list":["post-1767","post","type-post","status-publish","format-standard","hentry","category-examples-mysql"],"_links":{"self":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts\/1767","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/comments?post=1767"}],"version-history":[{"count":2,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts\/1767\/revisions"}],"predecessor-version":[{"id":1769,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts\/1767\/revisions\/1769"}],"wp:attachment":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/media?parent=1767"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/categories?post=1767"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/tags?post=1767"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}