Plugin Directory

Changeset 2010196


Ignore:
Timestamp:
01/10/2019 07:50:59 PM (7 years ago)
Author:
pcis
Message:

Error handling and functionality improvements

Location:
laiser-tag
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • laiser-tag/tags/1.2/include/OpenCalais/OpenCalais.php

    r2009527 r2010196  
    7979
    8080        if(is_a($response, 'WP_Error')) {
    81             throw new \Exception('WordPress API error, could not complete tagging.');
     81            error_log($response);
     82            throw new OpenCalaisException('WordPress API error, could not complete tagging: '.$response->get_error_message());
    8283        }
    8384
    8485        $object = json_decode($response['body']);
    8586        if (empty($object)) {
    86             error_log($response);
     87            error_log(print_r($response, true));
    8788            throw new OpenCalaisException('No response was received from the API.');
    8889        } elseif (isset($object->fault)) {
  • laiser-tag/tags/1.2/include/Tagging.php

    r2009527 r2010196  
    307307
    308308        // file check to stop this cron from running simultaneously
    309         if(file_exists(LTOC_PROCESS_FILE)) {
     309        if($this->isProcessRunning()) {
    310310            echo "in progress";
    311311            die;
    312312        }
    313313
    314         touch(LTOC_PROCESS_FILE);
    315314        unlink(LTOC_BATCH_LOG);
    316315        touch(LTOC_BATCH_LOG);
     
    355354            sleep(2);
    356355        }
     356        // unlink the process file, saves us having to check for the process later
    357357        unlink(LTOC_PROCESS_FILE);
    358358        $finalresult = "$tagged posts tagged successfully.";
     
    366366            $finalresult .= " $tags_not_stored posts returned tags but were not stored.";
    367367        }
    368 
    369         file_put_contents(LTOC_BATCH_LOG, date('Y-m-d H:i:s', time())." :: Batch process completed. $finalresult\n", FILE_APPEND);
     368        $this->batchLog("Batch process completed. $finalresult");
    370369    }
    371370
     
    524523        return $cat_parent_id;
    525524    }
     525
     526    private function isProcessRunning() {
     527        touch(LTOC_PROCESS_FILE);
     528        $last_pid = file_get_contents(LTOC_PROCESS_FILE);
     529        if(!empty($last_pid)) {
     530            exec('ps aux | grep "'.$last_pid.'"', $output, $result);
     531            foreach ($output as $line) {
     532                // compress spaces, then get the PID from the start of the line
     533                $line = preg_replace('/\s+/', ' ', $line);
     534                $splits = explode(' ', $line);
     535                $pid = $splits[1];
     536                if($pid == $last_pid) {
     537                    // then there is a process still running with the last recorded PID for this process
     538                    return true;
     539                }
     540            }
     541        }
     542        // at this point we're sure there is no other process running
     543        file_put_contents(LTOC_PROCESS_FILE, getmypid());
     544        return false;
     545    }
    526546}
  • laiser-tag/tags/1.2/laisertag.php

    r2009527 r2010196  
    99 * Plugin URI:        https://developer.wordpress.org/plugins/laiser-tag/
    1010 * Description:       Uses the OpenCalais API to automatically generate tags for existing posts.
    11  * Version:           1.2.0
     11 * Version:           1.2.1
    1212 * Author:            PCIS
    1313 * Author URI:        http://www.pcis.com/laiser-tag
     
    2121}
    2222
    23 define('LTOC_PLUGIN_VERSION', '1.2.0');
     23define('LTOC_PLUGIN_VERSION', '1.2.1');
    2424define('LTOC_PLUGIN_PATH', dirname(__FILE__));
    2525define('LTOC_TEMPLATES', dirname(__FILE__) . '/templates/');
  • laiser-tag/tags/1.2/readme.txt

    r2010168 r2010196  
    44Requires at least: 4.6
    55Tested up to: 5.0
    6 Stable tag: 1.2.0
     6Stable tag: 1.2.1
    77License: GPLv2 or later
    88License URI: https://www.gnu.org/licenses/gpl-2.0.html
     
    8888== Changelog ==
    8989
     90= 1.2.1 =
     91* Improved error handling
     92* Improved functionality for checking if the tagging cron is already running
     93
    9094= 1.2.0 =
    9195* Major UI changes; enhanced display and ease of use
  • laiser-tag/trunk/include/OpenCalais/OpenCalais.php

    r2009527 r2010196  
    7979
    8080        if(is_a($response, 'WP_Error')) {
    81             throw new \Exception('WordPress API error, could not complete tagging.');
     81            error_log($response);
     82            throw new OpenCalaisException('WordPress API error, could not complete tagging: '.$response->get_error_message());
    8283        }
    8384
    8485        $object = json_decode($response['body']);
    8586        if (empty($object)) {
    86             error_log($response);
     87            error_log(print_r($response, true));
    8788            throw new OpenCalaisException('No response was received from the API.');
    8889        } elseif (isset($object->fault)) {
  • laiser-tag/trunk/include/Tagging.php

    r2009521 r2010196  
    307307
    308308        // file check to stop this cron from running simultaneously
    309         if(file_exists(LTOC_PROCESS_FILE)) {
     309        if($this->isProcessRunning()) {
    310310            echo "in progress";
    311311            die;
    312312        }
    313313
    314         touch(LTOC_PROCESS_FILE);
    315314        unlink(LTOC_BATCH_LOG);
    316315        touch(LTOC_BATCH_LOG);
     
    355354            sleep(2);
    356355        }
     356        // unlink the process file, saves us having to check for the process later
    357357        unlink(LTOC_PROCESS_FILE);
    358358        $finalresult = "$tagged posts tagged successfully.";
     
    366366            $finalresult .= " $tags_not_stored posts returned tags but were not stored.";
    367367        }
    368 
    369         file_put_contents(LTOC_BATCH_LOG, date('Y-m-d H:i:s', time())." :: Batch process completed. $finalresult\n", FILE_APPEND);
     368        $this->batchLog("Batch process completed. $finalresult");
    370369    }
    371370
     
    524523        return $cat_parent_id;
    525524    }
     525
     526    private function isProcessRunning() {
     527        touch(LTOC_PROCESS_FILE);
     528        $last_pid = file_get_contents(LTOC_PROCESS_FILE);
     529        if(!empty($last_pid)) {
     530            exec('ps aux | grep "'.$last_pid.'"', $output, $result);
     531            foreach ($output as $line) {
     532                // compress spaces, then get the PID from the start of the line
     533                $line = preg_replace('/\s+/', ' ', $line);
     534                $splits = explode(' ', $line);
     535                $pid = $splits[1];
     536                if($pid == $last_pid) {
     537                    // then there is a process still running with the last recorded PID for this process
     538                    return true;
     539                }
     540            }
     541        }
     542        // at this point we're sure there is no other process running
     543        file_put_contents(LTOC_PROCESS_FILE, getmypid());
     544        return false;
     545    }
    526546}
  • laiser-tag/trunk/laisertag.php

    r2009521 r2010196  
    99 * Plugin URI:        https://developer.wordpress.org/plugins/laiser-tag/
    1010 * Description:       Uses the OpenCalais API to automatically generate tags for existing posts.
    11  * Version:           1.2.0
     11 * Version:           1.2.1
    1212 * Author:            PCIS
    1313 * Author URI:        http://www.pcis.com/laiser-tag
     
    2121}
    2222
    23 define('LTOC_PLUGIN_VERSION', '1.2.0');
     23define('LTOC_PLUGIN_VERSION', '1.2.1');
    2424define('LTOC_PLUGIN_PATH', dirname(__FILE__));
    2525define('LTOC_TEMPLATES', dirname(__FILE__) . '/templates/');
  • laiser-tag/trunk/readme.txt

    r2010168 r2010196  
    44Requires at least: 4.6
    55Tested up to: 5.0
    6 Stable tag: 1.2.0
     6Stable tag: 1.2.1
    77License: GPLv2 or later
    88License URI: https://www.gnu.org/licenses/gpl-2.0.html
     
    8888== Changelog ==
    8989
     90= 1.2.1 =
     91* Improved error handling
     92* Improved functionality for checking if the tagging cron is already running
     93
    9094= 1.2.0 =
    9195* Major UI changes; enhanced display and ease of use
Note: See TracChangeset for help on using the changeset viewer.