private static function __create(array $feedinfos, MySQLDB $db)
 {
     $feeds = array();
     foreach ($feedinfos as $feedinfo) {
         if (!isset($feedinfo['url'])) {
             throw new InvalidArgumentException('$feedinfos requires url attr');
         }
         $feed = MySQLFeed::find('url', $feedinfo['url'], $db);
         if ($feed === NULL) {
             $feeds[] = MySQLFeed::create($feedinfo, $db);
         } else {
             $feeds[] = $feed;
         }
     }
     $c = __CLASS__;
     return new $c($feeds, $db);
 }
 public static function testStories(MySQLDB $db = NULL)
 {
     if ($db === NULL) {
         $db = self::$site_db;
     }
     try {
         // MySQLFeed::get stories test (relies on MySQLFeed::create)
         $feed = MySQLFeed::create(self::$feedinfo, $db);
         $db->pdo->exec("INSERT INTO feed_stories\n\t\t    (title, content, url, time_stamp, sid, gid)\n\t\t     VALUES ('MySQLTest_title', 'MySQLTest_content',\n                             'MySQLTest_storyurl', " . time() . ",\n                             " . $feed->sid . ", 1);");
         $db->pdo->exec("INSERT INTO feed_stories\n\t\t    (title, content, url, time_stamp, sid, gid)\n\t\t     VALUES ('MySQLTest_title2', 'MySQLTest_content2',\n                             'MySQLTest_storyurl', " . time() . ",\n                             " . $feed->sid . ", 1);");
         $get_feedinfo = $feed->get(array('stories'), $db);
         $stories = $get_feedinfo['stories'];
         if ($get_feedinfo === NULL) {
             throw new Exception('MySQLFeed::get stories test failed');
         }
         // MySQLStories foreach test
         foreach ($stories as $story) {
             if (!$story instanceof MySQLStory) {
                 throw new Exception('MySQLStories foreach test failed');
             }
         }
         foreach ($stories as $story) {
             // MySQLStory::find test
             $find_story = MySQLStory::find('fid', $story->fid, $db);
             if ($find_story === NULL || $find_story->fid != $story->fid) {
                 throw new Exception('MySQLFeed::find test failed');
             }
             // MySQLStory::get test
             $get_storyinfo = $story->get(array('url'));
             if ($get_storyinfo['url'] != 'MySQLTest_storyurl') {
                 throw new Exception('MySQLStory::get test failed');
             }
             // MySQLStory::__get test
             $get_name = $story->get(array('content'));
             if ($story->content !== $get_name['content']) {
                 throw new Exception('MySQLStory::__get test failed');
             }
             $db->pdo->exec("DELETE FROM feed_stories WHERE fid={$story->fid};");
             /* XXX if this line is added and "SELECT * FROM feed_stories WHERE 
             	 url='MySQLTest_storyurl';" is run from the same system in the 'mysql'
             	 program, then the stories are not deleted below! */
             //throw new Exception();
         }
         $feed->delete();
     } catch (Exception $e) {
         if (isset($feed)) {
             $db->pdo->exec("DELETE FROM feed_stories WHERE sid={$feed->sid};");
             $feed->delete();
         }
         throw $e;
     }
 }