SHARE
TWEET

consume

a guest Feb 21st, 2019 86 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php namespace OpenFuego;
  2.  
  3. /** This script processes the data placed
  4.   * in the queue by collect.php.
  5. **/
  6.  
  7. use OpenFuego\lib\DbHandle as DbHandle;
  8. use OpenFuego\app\Consumer as Consumer;
  9. use OpenFuego\lib\Logger as Logger;
  10.  
  11. if (!defined('PHP_VERSION_ID') || PHP_VERSION_ID < 50300) {
  12.     die(__NAMESPACE__ . ' requires PHP 5.3.0 or higher.');
  13. }
  14.  
  15. if (php_sapi_name() != 'cli') {
  16.     die('This script must be invoked from the command line.');
  17. }
  18.  
  19. if (!defined('OPENFUEGO') && function_exists('pcntl_fork')) {
  20.     $error_message = "\n"
  21.         . 'Do not run this script directly. Run fetch.php to start.'
  22.         . "\n\n";
  23.     die($error_message);
  24. }
  25.  
  26. require_once(__DIR__ . '/init.php');
  27.  
  28. register_shutdown_function(function() {
  29.     Logger::fatal(__NAMESPACE__ . " consumer was terminated.");
  30. });
  31.  
  32. $dbh = new DbHandle();
  33.  
  34. $sql = "
  35. CREATE TABLE IF NOT EXISTS `openfuego_citizens` (
  36.   `user_id` bigint(20) unsigned NOT NULL,
  37.   `influence` tinyint(2) unsigned NOT NULL,
  38.   PRIMARY KEY (`user_id`)
  39. ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
  40.  
  41. CREATE TABLE IF NOT EXISTS `openfuego_links` (
  42.   `link_id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT,
  43.   `url` varchar(255) COLLATE utf8_unicode_ci NOT NULL DEFAULT '',
  44.   `first_seen` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
  45.   `first_tweet` bigint(20) unsigned NOT NULL,
  46.   `first_user` varchar(20) COLLATE utf8_unicode_ci NOT NULL DEFAULT '',
  47.   `first_user_id` bigint(20) unsigned DEFAULT NULL,
  48.   `weighted_count` smallint(5) unsigned NOT NULL,
  49.   `count` smallint(5) unsigned NOT NULL DEFAULT '1',
  50.   `last_seen` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
  51.   PRIMARY KEY (`link_id`),
  52.   UNIQUE KEY `url` (`url`)
  53. ) ENGINE=InnoDB  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
  54.  
  55. CREATE TABLE IF NOT EXISTS `openfuego_short_links` (
  56.   `id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT,
  57.   `input_url` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
  58.   `long_url` text COLLATE utf8_unicode_ci NOT NULL,
  59.   `last_seen` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  60.   PRIMARY KEY (`input_url`),
  61.   UNIQUE KEY `id` (`id`)
  62. ) ENGINE=InnoDB  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
  63.  
  64. CREATE TABLE IF NOT EXISTS `openfuego_tweets_cache` (
  65.   `link_id` mediumint(8) unsigned NOT NULL,
  66.   `id_str` bigint(20) unsigned NOT NULL,
  67.   `screen_name` varchar(15) COLLATE utf8_unicode_ci NOT NULL DEFAULT '',
  68.   `text` varchar(140) COLLATE utf8_unicode_ci NOT NULL DEFAULT '',
  69.   `profile_image_url` varchar(255) COLLATE utf8_unicode_ci NOT NULL DEFAULT '',
  70.   `modified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  71.   PRIMARY KEY (`link_id`)
  72. ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
  73.    
  74. ALTER TABLE `openfuego_tweets_cache`
  75.   ADD CONSTRAINT `FK.openfuego_tweets_cache.link_id` FOREIGN KEY (`link_id`) REFERENCES `openfuego_links` (`link_id`) ON DELETE CASCADE ON UPDATE CASCADE;
  76. ";
  77.  
  78. try {
  79.     $sth = $dbh->prepare($sql);
  80.     $sth->execute();
  81.  
  82. } catch (\PDOException $e) {
  83.     die($e);
  84. }
  85.  
  86. $dbh = NULL;
  87.  
  88. $consumer = new Consumer();
  89. $consumer->process();
  90.  
  91. exit;
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top