瀏覽代碼

Added model schema to docs; modified Model to set a MySQL style datetime (via Zend_Date) string for datetime fields

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@20190 44c647ce-9c0f-0410-b52a-842ac1e357ba
padraic 16 年之前
父節點
當前提交
f8f78410dc

+ 21 - 0
documentation/manual/en/module_specs/Zend_Feed_Pubsubhubbub.xml

@@ -283,6 +283,27 @@ if (!$publisher->isSuccess()) {
                 resulting class implements the interface
                 <classname>Zend_Feed_Pubsubhubbub_Model_SubscriptionInterface</classname>.
             </para>
+            
+            <para>
+                An example schema (MySQL) for a subscription table accessible by the provided model
+                may look similar to:
+            </para>
+            
+                    <programlisting language="sql"><![CDATA[
+CREATE TABLE IF NOT EXISTS `subscription` (
+  `id` bigint(20) NOT NULL AUTO_INCREMENT,
+  `topic_url` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
+  `hub_url` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
+  `created_time` datetime DEFAULT NULL,
+  `last_modified` datetime DEFAULT NULL,
+  `lease_seconds` bigint(20) DEFAULT NULL,
+  `verify_token` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
+  `secret` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
+  `expiration_time` datetime DEFAULT NULL,
+  `subscription_state` varchar(12) COLLATE utf8_unicode_ci DEFAULT NULL,
+  PRIMARY KEY (`id`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 ;
+]]></programlisting>
 
             <para>
                 Behind the scenes, the Subscriber above will send a request to the Hub endpoint containing the

+ 15 - 4
library/Zend/Feed/Pubsubhubbub/Subscriber.php

@@ -24,6 +24,11 @@
 require_once 'Zend/Feed/Pubsubhubbub.php';
 
 /**
+ * @see Zend_Date
+ */
+require_once 'Zend/Date.php';
+
+/**
  * @category   Zend
  * @package    Zend_Feed_Pubsubhubbub
  * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
@@ -732,20 +737,26 @@ class Zend_Feed_Pubsubhubbub_Subscriber
             $params['hub.lease_seconds'] = $this->getLeaseSeconds();
         }
 
-        // TODO: hub.secret not currently supported
+        // hub.secret not currently supported
         $optParams = $this->getParameters();
         foreach ($optParams as $name => $value) {
             $params[$name] = $value;
         }
         
         // store subscription to storage
+        $now = new Zend_Date;
+        $expires = null;
+        if (isset($params['hub.lease_seconds'])) {
+            $expires = $now->add($params['hub.lease_seconds'], Zend_Date::SECOND)
+                ->get('YYYY-MM-dd HH:mm:ss');
+        }
         $data = array(
             'id'                 => $key,
             'topic_url'          => $params['hub.topic'],
             'hub_url'            => $hubUrl,
-            'created_time'       => time(),
-            'last_modified'      => time(),
-            'lease_seconds'      => isset($params['hub.lease_seconds']) ? $params['hub.lease_seconds'] : null,
+            'created_time'       => $now->get('YYYY-MM-dd HH:mm:ss'),
+            'last_modified'      => $now->get('YYYY-MM-dd HH:mm:ss'),
+            'lease_seconds'      => $expires,
             'verify_token'       => hash('sha256', $params['hub.verify_token']),
             'secret'             => null,
             'expiration_time'    => isset($params['hub.lease_seconds']) ? time() + $params['hub.lease_seconds'] : null,