Support cancelling and killing backend processes in 7.5
authorchriskl <chriskl>
Thu, 8 Jul 2004 03:23:01 +0000 (03:23 +0000)
committerchriskl <chriskl>
Thu, 8 Jul 2004 03:23:01 +0000 (03:23 +0000)
HISTORY
classes/Misc.php
classes/database/BaseDB.php
classes/database/Postgres75.php
database.php
lang/english.php
lang/recoded/english.php

diff --git a/HISTORY b/HISTORY
index 09b7c218677949a76e61b6f06c2c7fda7d3ff86e..cf137e4e8aa607ad796582a6c367a453d91d4c5c 100644 (file)
--- a/HISTORY
+++ b/HISTORY
@@ -8,6 +8,7 @@ Features
 * Context-sensitive online help system
 * Use language preferencies from browser (Markus Bertheau, Nicola Soranzo)
 * Tablespace support for 7.5
+* Support cancelling and killing backend processes in 7.5
 
 Translations
 * Arabic from Zaki
index 44564ed2a33ecc8b2f7e5f8a52ff9b79f5da3f39..a2bf41559c807a59dc0c1da87b67c3e6d47c0423 100644 (file)
@@ -2,7 +2,7 @@
        /**
         * Class to hold various commonly used functions
         *
-        * $Id: Misc.php,v 1.67 2004/07/07 03:00:01 chriskl Exp $
+        * $Id: Misc.php,v 1.68 2004/07/08 03:23:01 chriskl Exp $
         */
         
        class Misc {
                function printTable(&$tabledata, &$columns, &$actions, $nodata = null, $pre_fn = null) {
                        global $data, $conf, $misc;
                        global $PHP_SELF;
-                       
+
                        if ($tabledata->recordCount() > 0) {
                                
                                // Remove the 'comment' column if they have been disabled
index 4f355873e8070e8a41ed953fb62b82f1906152c6..7b337b3aa299ecd5a166687ac731d331ab2ccbfd 100644 (file)
@@ -4,7 +4,7 @@
  * A class that implements the DB interface for Postgres
  * Note: This class uses ADODB and returns RecordSets.
  *
- * $Id: BaseDB.php,v 1.49 2004/07/04 15:02:35 chriskl Exp $
+ * $Id: BaseDB.php,v 1.50 2004/07/08 03:23:02 chriskl Exp $
  */
 
 include_once('./classes/database/ADODB_base.php');
@@ -283,6 +283,7 @@ class BaseDB extends ADODB_base {
        function hasForeignKeysInfo() { return false; }
        function hasViewColumnRename() { return false; }
        function hasTablespaces() { return false; }
+       function hasSignals() { return false; }
 
 }
 
index c71cefa23400bc10c4dc3b58755783479a3e2f63..42f37da629c12213c9becfb8f37462535d914835 100755 (executable)
@@ -3,7 +3,7 @@
 /**
  * PostgreSQL 7.5 support
  *
- * $Id: Postgres75.php,v 1.9 2004/07/07 03:00:07 chriskl Exp $
+ * $Id: Postgres75.php,v 1.10 2004/07/08 03:23:02 chriskl Exp $
  */
 
 include_once('./classes/database/Postgres74.php');
@@ -267,11 +267,40 @@ class Postgres75 extends Postgres74 {
                                
                return $this->endTransaction();
        }
+       
+       // Backend process signalling functions
+       
+       /**
+        * Sends a cancel or kill command to a process
+        * @param $pid The ID of the backend process
+        * @param $signal 'CANCEL' or 'KILL'
+        * @return 0 success
+        * @return -1 invalid signal type
+        */
+       function sendSignal($pid, $signal) {
+               // Clean
+               $pid = (int)$pid;
+               
+               if ($signal == 'CANCEL')
+                       $sql = "SELECT pg_catalog.pg_cancel_backend({$pid}) AS val";
+               elseif ($signal == 'KILL')
+                       $sql = "SELECT pg_catalog.pg_terminate_backend({$pid}) AS val";
+               else
+                       return -1;
+                       
+               // Execute the query
+               $val = $this->selectField($sql, 'val');
                
+               if ($val === -1) return -1;
+               elseif ($val == '1') return 0;
+               else return -1;
+       }
+       
        function hasAlterColumnType() { return true; }
        function hasTablespaces() { 
                $platform = $this->getPlatform();
                return $platform != 'MINGW';
        }
+       function hasSignals() { return true; }
        
 }
index ca45b44416aabbd9d6c099b909e76ba7c4a9674c..ab590706673acdaef85345b84c667ea9cc0fbc51 100755 (executable)
@@ -3,7 +3,7 @@
        /**
         * Manage schemas within a database
         *
-        * $Id: database.php,v 1.50 2004/07/07 02:59:56 chriskl Exp $
+        * $Id: database.php,v 1.51 2004/07/08 03:23:01 chriskl Exp $
         */
 
        // Include application functions
                return str_replace($term, "<b>{$term}</b>", $string);
        }       
 
+       /**
+        * Sends a signal to a process
+        */
+       function doSignal() {
+               global $data, $lang;
+
+               $status = $data->sendSignal($_REQUEST['procpid'], $_REQUEST['signal']);
+               if ($status == 0)
+                       doProcesses($lang['strsignalsent']);
+               else
+                       doProcesses($lang['strsignalsentbad']);
+       }
+
        /**
         * Searches for a named database object
         */
         * Show all current database connections and any queries they
         * are running.
         */
-       function doProcesses() {
+       function doProcesses($msg = '') {
                global $PHP_SELF, $data, $misc;
                global $lang;
 
                $processes = &$data->getProcesses($_REQUEST['database']);
                
                $misc->printDatabaseNav();
-               $misc->printTitle(array($misc->printVal($_REQUEST['database']),$lang['strprocesses']),'processes');
-
+               $misc->printTitle(array($misc->printVal($_REQUEST['database']), $lang['strprocesses']), 'processes');
+               $misc->printMsg($msg);
+               
                $columns = array(
                        'user' => array(
                                'title' => $lang['strusername'],
                                'field' => 'query_start',
                        ),
                );
-               
-               $actions = array();
+
+               if ($data->hasSignals()) {
+                       $columns['actions'] = array('title' => $lang['stractions']);
+
+                       $actions = array(
+                               'cancel' => array(
+                                       'title' => $lang['strcancel'],
+                                       'url'   => "{$PHP_SELF}?action=signal&amp;signal=CANCEL&amp;database=" . urlencode($_REQUEST['database']) . "&amp;",
+                                       'vars'  => array('procpid' => 'procpid')
+                               ),
+                               'kill' => array(
+                                       'title' => $lang['strkill'],
+                                       'url'   => "{$PHP_SELF}?action=signal&amp;signal=KILL&amp;database=" . urlencode($_REQUEST['database']) . "&amp;",
+                                       'vars'  => array('procpid' => 'procpid')
+                               )
+                       );
+               }
+               else $actions = array();
                
                // Remove query start time for <7.4
                if (!isset($processes->f['query_start'])) unset($columns['start_time']);
                case 'export':
                        doExport();
                        break;
+               case 'signal':
+                       doSignal();
+                       break;
                default:
                        if ($data->hasSchemas())
                                doDefault();
index 7d2335a9bc958cf489804b2b513cc133940b9406..246bcfc63cc305ca9e73c7eb82665cbe23f00d54 100755 (executable)
@@ -4,7 +4,7 @@
         * English language file for phpPgAdmin.  Use this as a basis
         * for new translations.
         *
-        * $Id: english.php,v 1.151 2004/07/07 03:00:07 chriskl Exp $
+        * $Id: english.php,v 1.152 2004/07/08 03:23:02 chriskl Exp $
         */
 
        // Language and character set
        $lang['strstarttime'] = 'Start Time';
        $lang['strfile'] = 'File';
        $lang['strfileimported'] = 'File imported.';
+       $lang['strkill'] = 'Kill';
 
        // Error handling
        $lang['strnoframes'] = 'You need a frames-enabled browser to use this application.';
        $lang['strfull'] = 'Full';
        $lang['strfreeze'] = 'Freeze';
        $lang['strforce'] = 'Force';
+       $lang['strsignalsent'] = 'Signal sent.';
+       $lang['strsignalsentbad'] = 'Failed sending signal.';
 
        // Views
        $lang['strview'] = 'View';
index f157b41a7086e120ba62f0b7cefeef6641f6a9b2..0b4a95908170ae1a7dd9e5b13d253d1910934f49 100644 (file)
@@ -4,7 +4,7 @@
         * English language file for phpPgAdmin.  Use this as a basis
         * for new translations.
         *
-        * $Id: english.php,v 1.104 2004/07/07 03:00:07 chriskl Exp $
+        * $Id: english.php,v 1.105 2004/07/08 03:23:02 chriskl Exp $
         */
 
        // Language and character set
        $lang['strstarttime'] = 'Start Time';
        $lang['strfile'] = 'File';
        $lang['strfileimported'] = 'File imported.';
+       $lang['strkill'] = 'Kill';
 
        // Error handling
        $lang['strnoframes'] = 'You need a frames-enabled browser to use this application.';
        $lang['strfull'] = 'Full';
        $lang['strfreeze'] = 'Freeze';
        $lang['strforce'] = 'Force';
+       $lang['strsignalsent'] = 'Signal sent.';
+       $lang['strsignalsentbad'] = 'Failed sending signal.';
 
        // Views
        $lang['strview'] = 'View';