svn: /pear/pearweb/trunk/ include/pear-database-channel.php public_html/channels/add.php public_html/channels/edit.php

[email protected] ("Daniel O'Connor") Sat, 09 Apr 2011 15:03:43 +0000
Newsgroups php.pear.cvs,php.pear.core
Message-ID <[email protected]>
clockwerx                                Sat, 09 Apr 2011 15:03:43 +0000

Revision: http://svn.php.net/viewvc?view=revision&revision=310098

Log:
Cleanup, activate/deactivate added

Changed paths:
    U   pear/pearweb/trunk/include/pear-database-channel.php
    U   pear/pearweb/trunk/public_html/channels/add.php
    U   pear/pearweb/trunk/public_html/channels/edit.php
svn-diffs-310098.txt (text/x-diff, 10.6 KB)
Modified: pear/pearweb/trunk/include/pear-database-channel.php
===================================================================
--- pear/pearweb/trunk/include/pear-database-channel.php	2011-04-09 14:48:25 UTC (rev 310097)
+++ pear/pearweb/trunk/include/pear-database-channel.php	2011-04-09 15:03:43 UTC (rev 310098)
@@ -57,6 +57,16 @@
         }
     }

+    static function deactivate($name)
+    {
+        global $dbh;
+        $query = "UPDATE channels SET is_active = 0 WHERE name = ?";
+        $err = $dbh->query($query, array($name));
+        if (DB::isError($err)) {
+            return $err;
+        }
+    }
+
     static function remove($name)
     {
         global $dbh;

Modified: pear/pearweb/trunk/public_html/channels/add.php
===================================================================
--- pear/pearweb/trunk/public_html/channels/add.php	2011-04-09 14:48:25 UTC (rev 310097)
+++ pear/pearweb/trunk/public_html/channels/add.php	2011-04-09 15:03:43 UTC (rev 310098)
@@ -79,17 +79,17 @@
                              "email" => $auth_user->email)));
 }

-$name = $form->addElement("text", "name", array('required' => 'required', 'placeholder' => 'John Doe'));
-$name->setLabel("Your name");
-$name->addFilter("htmlspecialchars");
-$name->addRule('required', "Please enter your name");
+$contact_name = $form->addElement("text", "name", array('required' => 'required', 'placeholder' => 'John Doe'));
+$contact_name->setLabel("Your name");
+$contact_name->addFilter("htmlspecialchars");
+$contact_name->addRule('required', "Please enter your name");

-$email = $form->addElement("email", "email", array('required' => 'required', '[email protected]'));
-$email->setLabel("Email");
-$email->addFilter("htmlspecialchars");
+$contact_email = $form->addElement("email", "contact_email", array('required' => 'required', '[email protected]'));
+$contact_email->setLabel("Email");
+$contact_email->addFilter("htmlspecialchars");

-$email->addRule('required', "Please enter your email address");
-$email->addRule('callback', '', array('callback'  => 'filter_var',
+$contact_email->addRule('required', "Please enter your email address");
+$contact_email->addRule('callback', '', array('callback'  => 'filter_var',
                                       'arguments' => array(FILTER_VALIDATE_EMAIL)));

 $project_name = $form->addElement("text", "project[name]", array('required' => 'required', 'placeholder' => 'pear.phpunit.de'));
@@ -117,14 +117,14 @@
         $req = new HTTP_Request2;

         $req->setURL($url->getScheme() . "://" . $url->getHost() . ":" . $url->getPort() . "/channel.xml");
-        channel::validate($req, $chan, $project_name);
+        channel::validate($req, $chan);

         if ($url->getHost() != $chan->getServer()) {
             throw new Exception("Channel server for wrong host");
         }


-        if (channel::exists($project_name)) {
+        if (channel::exists($project_name->getValue())) {
             throw new Exception("Already exists");
         }

@@ -134,8 +134,8 @@
                         $project_name->getValue(),
                         $project_link->getValue());
         $from = sprintf('"%s" <%s>',
-                        $name->getValue(),
-                        $email->getValue());
+                        $contact_name->getValue(),
+                        $contact_email->getValue());

         $logger = new Damblan_Log;

@@ -148,8 +148,8 @@
         $logger->log($text);

         // Add the channel to the DB, but not yet activated
-        channel::add($project_name);
-        channel::edit($project_name, $project_label, $project_link, $name, $email);
+        channel::add($project_name->getValue());
+        channel::edit($project_name->getValue(), $project_label->getValue(), $project_link->getValue(), $contact_name->getValue(), $contact_email->getValue());


         echo "<div class=\"success\">Thanks for your submission.  It will ";
@@ -159,25 +159,11 @@

         switch ($exception->getMessage()) {
             case "Invalid channel site":
-                echo "The submitted URL does not ";
-                echo "appear to point to a valid channel site.  You will ";
-                echo "have to make sure that <tt>/channel.xml</tt> at least ";
-                echo "exists and is valid.";
-            break;
-
             case "Empty channel.xml":
                 echo "The submitted URL does not ";
                 echo "appear to point to a valid channel site.  You will ";
                 echo "have to make sure that <tt>/channel.xml</tt> at least ";
                 echo "exists and is valid.";
-            break;
-
-            case "Channel.xml too large":
-                echo "The submitted URL does not ";
-                echo "appear to point to a valid channel site.  You will ";
-                echo "have to make sure that <tt>/channel.xml</tt> at least ";
-                echo "exists and is not huge.";
-            break;
             default:
                 echo $exception->getMessage();
             break;

Modified: pear/pearweb/trunk/public_html/channels/edit.php
===================================================================
--- pear/pearweb/trunk/public_html/channels/edit.php	2011-04-09 14:48:25 UTC (rev 310097)
+++ pear/pearweb/trunk/public_html/channels/edit.php	2011-04-09 15:03:43 UTC (rev 310098)
@@ -53,7 +53,7 @@
     die("Invalid channel specified");
 }

-$channel = $dbh->query("SELECT * FROM channels WHERE name = ?", array($_GET['channel']), DB_FETCHMODE_ASSOC);
+$channel = $dbh->query("SELECT * FROM channels WHERE name = ?", array($_GET['channel']))->fetchRow(DB_FETCHMODE_ASSOC);

 $chan = new PEAR_ChannelFile;

@@ -78,38 +78,32 @@
 $form = new HTML_QuickForm2("submitForm");
 $form->removeAttribute('name');

-$form->addDataSource(new HTML_QuickForm2_DataSource_Array(array("name" => $channel['contact_name'],
-                         "email" => $channel['contact_email'],
-                         "project[label]" => $channel["project_label"],
-                         "project[link]" => $channel["project_link"],
+$form->addDataSource(new HTML_QuickForm2_DataSource_Array(array("contact_name" => $channel['contact_name'],
+                         "contact_email" => $channel['contact_email'],
+                         "project_label" => $channel["project_label"],
+                         "project_link" => $channel["project_link"],
                          "is_active" => 1,
                         )));

-$name = $form->addElement("text", "name", array('required' => 'required', 'placeholder' => 'John Doe'));
-$name->setLabel("Your name");
-$name->addFilter("htmlspecialchars");
-$name->addRule('required', "Please enter your name");
+$contact_name = $form->addElement("text", "contact_name", array('required' => 'required', 'placeholder' => 'John Doe'));
+$contact_name->setLabel("Your name");
+$contact_name->addFilter("htmlspecialchars");
+$contact_name->addRule('required', "Please enter your name");

-$email = $form->addElement("email", "email", array('required' => 'required', '[email protected]'));
-$email->setLabel("Email");
-$email->addFilter("htmlspecialchars");
+$contact_email = $form->addElement("email", "contact_email", array('required' => 'required', '[email protected]'));
+$contact_email->setLabel("Email");
+$contact_email->addFilter("htmlspecialchars");

-$email->addRule('required', "Please enter your email address");
-$email->addRule('callback', '', array('callback'  => 'filter_var',
+$contact_email->addRule('required', "Please enter your email address");
+$contact_email->addRule('callback', '', array('callback'  => 'filter_var',
                                       'arguments' => array(FILTER_VALIDATE_EMAIL)));

-$project_name = $form->addElement("text", "project[name]", array('required' => 'required', 'placeholder' => 'pear.phpunit.de'));
-
-$project_name->setLabel("Channel discover");
-$project_name->addFilter("htmlspecialchars");
-$project_name->addRule('required', "Please enter your project channel discover line");
-
-$project_label = $form->addElement("text", "project[label]", array('required' => 'required', 'placeholder' => 'PHPUnit'));
+$project_label = $form->addElement("text", "project_label", array('required' => 'required', 'placeholder' => 'PHPUnit'));
 $project_label->setLabel("Project Name");
 $project_label->addFilter("htmlspecialchars");
 $project_label->addRule('required', "Please enter your project name");

-$project_link = $form->addElement("url", "project[link]", array('required' => 'required', 'placeholder' => 'http://pear.phpunit.de/'));
+$project_link = $form->addElement("url", "project_link", array('required' => 'required', 'placeholder' => 'http://pear.phpunit.de/'));
 $project_link->setLabel("Project Homepage");
 $project_link->addFilter("htmlspecialchars");
 $project_link->addRule('required', "Please enter your project link");
@@ -126,27 +120,27 @@
         $req = new HTTP_Request2;

         $req->setURL($url->getScheme() . "://" . $url->getHost() . ":" . $url->getPort() . "/channel.xml");
-        channel::validate($req, $chan, $project_name);
+        channel::validate($req, $chan);

         if ($url->getHost() != $chan->getServer()) {
             throw new Exception("Channel server for wrong host");
         }

-        channel::edit($project_name, $project_label, $project_link, $name, $email);
+        channel::edit($channel['name'], $project_label->getValue(), $project_link->getValue(), $contact_name->getValue(), $contact_email->getValue());

+        if ($is_active->getValue()) {
+            channel::activate($channel['name']);
+        } else {
+            channel::deactivate($channel['name']);
+        }

+
         echo "<div class=\"success\">Changes saved</div>\n";
     } catch (Exception $exception) {
         echo '<div class="errors">';

         switch ($exception->getMessage()) {
             case "Invalid channel site":
-                echo "The submitted URL does not ";
-                echo "appear to point to a valid channel site.  You will ";
-                echo "have to make sure that <tt>/channel.xml</tt> at least ";
-                echo "exists and is valid.";
-            break;
-
             case "Empty channel.xml":
                 echo "The submitted URL does not ";
                 echo "appear to point to a valid channel site.  You will ";
@@ -154,12 +148,6 @@
                 echo "exists and is valid.";
             break;

-            case "Channel.xml too large":
-                echo "The submitted URL does not ";
-                echo "appear to point to a valid channel site.  You will ";
-                echo "have to make sure that <tt>/channel.xml</tt> at least ";
-                echo "exists and is not huge.";
-            break;
             default:
                 echo $exception->getMessage();
             break;