public function initializeNodes()
 {
     DB::table('nodes')->truncate();
     $node_array = ['交流' => ['经验' => ['slug' => 'experience', 'description' => '分享你在从事远程工作或远程协作过程中所收获的经验与教训,把你遇到的“坑”分享给每一个希望知道的人!'], '问答' => ['slug' => 'question', 'description' => '有问必答,用心解决每个人的实际中遇到的问题!'], '项目' => ['slug' => 'project ', 'description' => '你可以发布需要远程工作者参与的任何合法项目!'], '工作' => ['slug' => 'job', 'description' => '真正的工作,并不是外包,如果你需要真正的远程工作者成为您正式的同事,请在这里发布您的招聘!'], '远程团队' => ['slug' => 'createteam', 'description' => '每个人都应该有自己的团队,在这里我们寻找志同道合多人!'], '实战训练' => ['slug' => 'training ', 'description' => '真正的技术只有通过实战,才能得以证实!想要提升技能,让我们一起发布实战训练!'], '每周必读' => ['slug' => 'requiredread', 'description' => '每周一篇,汇聚本周你必须知道的事!'], '线上活动' => ['slug' => 'activity', 'description' => '在线举办的所有活动,都将发布在这里'], '线下聚会' => ['slug' => 'gathering', 'description' => '线下聚会,怎能没有你']], '社区' => ['公告' => ['slug' => 'announcement', 'description' => ''], '反馈' => ['slug' => 'feedback', 'description' => '对于社区的优化或者 bug report , 可以在此节点下提'], '社区开发' => ['slug' => 'community-development', 'description' => '构建此社区软件的开发讨论节点']]];
     $top_nodes = array();
     foreach ($node_array as $key => $value) {
         $top_nodes[] = ['name' => $key];
     }
     DB::table('nodes')->insert($top_nodes);
     $nodes = array();
     foreach ($node_array as $key => $value) {
         $top_node = Node::where('name', '=', $key)->first();
         foreach ($value as $snode => $svalue) {
             $nodes[] = ['parent_node' => $top_node->id, 'name' => $snode, 'slug' => $svalue['slug'], 'description' => $svalue['description']];
         }
     }
     DB::table('nodes')->insert($nodes);
 }
 public function initializeNodes()
 {
     DB::table('nodes')->truncate();
     $node_array = ['PHP' => ['php' => ['slug' => 'php', 'description' => 'PHP(PHP: Hypertext Preprocessor 的縮寫,中文名:“PHP:超文本預處理器”)是一種通用開源腳本語言。'], 'Laravel' => ['slug' => 'laravel', 'description' => 'Laravel是一套簡潔、優雅的 PHP Web 開發框架(PHP Web Framework)。它可以讓你從像麵條一樣雜亂的程式碼中解脫出來;它可以幫你構建一個完美的網路應用程式,而且每行程式碼都可以簡潔、富於表達力。'], 'Composer & Packagist' => ['slug' => 'composer-and-packagist', 'description' => 'Composer[1] 是PHP中用來管理依賴(dependency)關係的工具。你可以在自己的項目中聲明所依賴的外部工具庫(libraries),Composer 會幫你安裝這些依賴的庫檔案。'], '重構' => ['slug' => 'refactoring', 'description' => '由於軟體發展本身不可能是完美的,因此改進的過程是持續且必然的,重構的方式將作為改善軟體設計的一種手段和方式,更加地擁有現實意義。'], '設計模式' => ['slug' => 'design-pattern', 'description' => '設計模式(Design pattern)是一套被反覆使用、多數人知曉的、經過分類編目的、程式碼設計經驗的總結。使用設計模式是為了可重用程式碼、讓程式碼更容易被他人理解、保證程式碼可靠性。'], 'Testing' => ['slug' => 'testing', 'description' => '軟體測試(software testing),描述一種用來促進鑒定軟體的正確性、完整性、安全性和品質的過程。'], '部署' => ['slug' => 'deployment', 'description' => ''], '開源項目' => ['slug' => 'opensource-project', 'description' => '']], 'Web 開發' => ['MySQL' => ['slug' => 'mysql', 'description' => 'MySQL 是一個關係型資料庫管理系統,由瑞典 MySQL AB 公司開發,目前屬於 Oracle 公司。'], 'Database' => ['slug' => 'database', 'description' => '資料庫(Database)是按照資料結構來組織、存儲和管理數據的倉庫'], 'Git' => ['slug' => 'git', 'description' => 'Git 是一個開源的分散式版本控制系統,用以有效、高速的處理從很小到非常大的項目版本管理。'], 'Linux' => ['slug' => 'linux', 'description' => 'Linux 是一種自由和開放源碼的類 Unix 操作系統,存在著許多不同的 Linux 版本,但它們都使用了 Linux 核心。'], 'WebServer' => ['slug' => 'web-server', 'description' => 'WEB 伺服器也稱為 WWW (WORLD WIDE WEB) 伺服器,主要功能是提供網上信息瀏覽服務。常見的有 Nginx, Apache..'], '演算法' => ['slug' => 'algrithm', 'description' => '演算法(Algorithm)是指解題方案的準確而完整的描述,是一系列解決問題的清晰指令,演算法代表著用系統的方法描述解決問題的策略機制。'], '營運' => ['slug' => 'operations', 'description' => ''], '安全' => ['slug' => 'security', 'description' => ''], '雲端服務' => ['slug' => 'cloud-service', 'description' => '雲端服務開發這一概念包含幾種不同的開發類型 - 軟體即服務(SaaS), 平台即服務(PaaS), Web 服務, 隨選 (on—demand) 運算']], 'Mobile' => ['iPhone' => ['slug' => 'iphone-development', 'description' => 'iPhone 開發'], 'Android' => ['slug' => 'android-development', 'description' => 'Android 開發']], 'Languages' => ['JavaScript' => ['slug' => 'javascript', 'description' => 'JavaScript 是一種基于對象和事件驅動並具有相對安全性的客戶端腳本語言。'], 'Ruby' => ['slug' => 'ruby', 'description' => 'Ruby,一種為簡單快捷的面向對象編程(面向對象程序設計)而創的腳本語言'], 'Python' => ['slug' => 'python', 'description' => 'Python, 是一種面向對象、直譯式計算機程序設計語言'], 'GoLang' => ['slug' => 'golang', 'description' => 'Go 語言是谷歌推出的一種全新的編程語言,可以在不損失應用程序性能的情況下降低程式碼的複雜性。'], 'Erlang' => ['slug' => 'erlang', 'description' => 'Erlang 是一種通用的面向並發的編程語言,它由瑞典電信設備製造商愛立信所轄的 CS-Lab 開發,目的是創造一種可以應對大規模並發活動的編程語言和運行環境。']], '社群' => ['公告' => ['slug' => 'announcement', 'description' => ''], '反饋' => ['slug' => 'feedback', 'description' => '對於社群的優化或者 bug report , 可以在此分類下提'], '社群開發' => ['slug' => 'community-development', 'description' => '構建此社群軟體的開發討論分類'], '實體聚會' => ['slug' => 'gathering', 'description' => '']], '分享' => ['健康' => ['slug' => 'health', 'description' => ''], '工具' => ['slug' => 'toolings', 'description' => '使用工具, 是人類文明的標誌'], '其他' => ['slug' => 'other-share', 'description' => '抱歉, 如果你分享的話題不屬於其他分類的話, 只能選擇這裡了. '], '書籍' => ['slug' => 'book-share', 'description' => '書籍是知識載體, 讓我們一起站在巨人的肩膀上. '], '求職' => ['slug' => 'request-a-job', 'description' => '介紹下你自己, 讓大家幫你找到一份好的工作'], '招聘' => ['slug' => 'hire', 'description' => '這裡有高品質的 PHPer, 記得認真填寫你的需求, 薪資待遇是必須寫的哦.'], '創業' => ['slug' => 'start-up', 'description' => ''], '移民' => ['slug' => 'immigration', 'description' => '']]];
     $top_nodes = array();
     foreach ($node_array as $key => $value) {
         $top_nodes[] = ['name' => $key];
     }
     DB::table('nodes')->insert($top_nodes);
     $nodes = array();
     foreach ($node_array as $key => $value) {
         $top_node = Node::where('name', '=', $key)->first();
         foreach ($value as $snode => $svalue) {
             $nodes[] = ['parent_node' => $top_node->id, 'name' => $snode, 'slug' => $svalue['slug'], 'description' => $svalue['description']];
         }
     }
     DB::table('nodes')->insert($nodes);
 }
 public function initializeNodes()
 {
     DB::table('nodes')->truncate();
     $node_array = ['PHP' => ['php' => ['slug' => 'php', 'description' => 'PHP(PHP: Hypertext Preprocessor的缩写,中文名:“PHP:超文本预处理器”)是一种通用开源脚本语言。'], 'Laravel' => ['slug' => 'laravel', 'description' => 'Laravel是一套简洁、优雅的PHP Web开发框架(PHP Web Framework)。它可以让你从面条一样杂乱的代码中解脱出来;它可以帮你构建一个完美的网络APP,而且每行代码都可以简洁、富于表达力。'], 'Composer & Packagist' => ['slug' => 'composer-and-packagist', 'description' => 'Composer[1]是PHP中用来管理依赖(dependency)关系的工具。你可以在自己的项目中声明所依赖的外部工具库(libraries),Composer会帮你安装这些依赖的库文件。'], '重构' => ['slug' => 'refactoring', 'description' => '由于软件发展本身不可能是完美的,因此改进的过程是持续且必然的,重构的方式将作为改善软件设计的一种手段和方式,更加地拥有现实意义。'], '设计模式' => ['slug' => 'design-pattern', 'description' => '设计模式(Design pattern)是一套被反复使用、多数人知晓的、经过分类编目的、代码设计经验的总结。使用设计模式是为了可重用代码、让代码更容易被他人理解、保证代码可靠性。'], 'Testing' => ['slug' => 'testing', 'description' => '软件测试(英语:software testing),描述一种用来促进鉴定软件的正确性、完整性、安全性和质量的过程。'], '部署' => ['slug' => 'deployment', 'description' => ''], '开源项目' => ['slug' => 'opensource-project', 'description' => '']], 'Web 开发' => ['MySQL' => ['slug' => 'mysql', 'description' => 'MySQL是一个关系型数据库管理系统,由瑞典MySQL AB公司开发,目前属于Oracle公司。'], 'Database' => ['slug' => 'database', 'description' => '数据库(Database)是按照数据结构来组织、存储和管理数据的仓库'], 'Git' => ['slug' => 'git', 'description' => 'Git是一个开源的分布式版本控制系统,用以有效、高速的处理从很小到非常大的项目版本管理。'], 'Linux' => ['slug' => 'linux', 'description' => 'Linux是一种自由和开放源码的类Unix操作系统,存在着许多不同的Linux版本,但它们都使用了Linux内核。'], 'WebServer' => ['slug' => 'web-server', 'description' => 'WEB服务器也称为WWW(WORLD WIDE WEB)服务器,主要功能是提供网上信息浏览服务。常见的有 Nginx, Apache..'], '算法' => ['slug' => 'algrithm', 'description' => '算法(Algorithm)是指解题方案的准确而完整的描述,是一系列解决问题的清晰指令,算法代表着用系统的方法描述解决问题的策略机制。'], '运维' => ['slug' => 'operations', 'description' => ''], '安全' => ['slug' => 'security', 'description' => ''], '云服务' => ['slug' => 'cloud-service', 'description' => '云服务开发这一概念包含几种不同的开发类型 - 软件即服务(SaaS), 平台即服务(PaaS), Web服务, 按需(on—demand)计算']], 'Mobile' => ['iPhone' => ['slug' => 'iphone-development', 'description' => 'iPhone 开发'], 'Android' => ['slug' => 'android-development', 'description' => 'Android 开发']], 'Languages' => ['JavaScript' => ['slug' => 'javascript', 'description' => 'JavaScript是一种基于对象和事件驱动并具有相对安全性的客户端脚本语言。'], 'Ruby' => ['slug' => 'ruby', 'description' => 'Ruby,一种为简单快捷的面向对象编程(面向对象程序设计)而创的脚本语言'], 'Python' => ['slug' => 'python', 'description' => 'Python, 是一种面向对象、直译式计算机程序设计语言'], 'GoLang' => ['slug' => 'golang', 'description' => 'Go语言是谷歌推出的一种全新的编程语言,可以在不损失应用程序性能的情况下降低代码的复杂性。'], 'Erlang' => ['slug' => 'erlang', 'description' => 'Erlang是一种通用的面向并发的编程语言,它由瑞典电信设备制造商爱立信所辖的CS-Lab开发,目的是创造一种可以应对大规模并发活动的编程语言和运行环境。']], '社区' => ['公告' => ['slug' => 'announcement', 'description' => ''], '反馈' => ['slug' => 'feedback', 'description' => '对于社区的优化或者 bug report , 可以在此节点下提'], '社区开发' => ['slug' => 'community-development', 'description' => '构建此社区软件的开发讨论节点'], '线下聚会' => ['slug' => 'gathering', 'description' => '']], '分享' => ['健康' => ['slug' => 'health', 'description' => ''], '工具' => ['slug' => 'toolings', 'description' => '使用工具, 是人类文明的标志'], '其他' => ['slug' => 'other-share', 'description' => '抱歉, 如果你分享的话题不属于其他节点的话, 只能选择这里咯. '], '书籍' => ['slug' => 'book-share', 'description' => '书籍是知识载体, 让我们一起站在巨人的肩膀上. '], '求职' => ['slug' => 'request-a-job', 'description' => '介绍下你自己, 让大家帮你找到一份好的工作'], '招聘' => ['slug' => 'hire', 'description' => '这里有高质量的 PHPer, 记得认真填写你的需求, 薪资待遇是必须写的哦.'], '创业' => ['slug' => 'start-up', 'description' => ''], '移民' => ['slug' => 'immigration', 'description' => '']]];
     $top_nodes = array();
     foreach ($node_array as $key => $value) {
         $top_nodes[] = ['name' => $key];
     }
     DB::table('nodes')->insert($top_nodes);
     $nodes = array();
     foreach ($node_array as $key => $value) {
         $top_node = Node::where('name', '=', $key)->first();
         foreach ($value as $snode => $svalue) {
             $nodes[] = ['parent_node' => $top_node->id, 'name' => $snode, 'slug' => $svalue['slug'], 'description' => $svalue['description']];
         }
     }
     DB::table('nodes')->insert($nodes);
 }
 public function fire($job, $data)
 {
     $output = new Symfony\Component\Console\Output\ConsoleOutput();
     $json_array = json_decode($data['message']);
     $service_provider = new $json_array->service_provider();
     # Ensure the integration still exists. If not, delete all the nodes and remove the job from the queue forever.
     try {
         $integration = Integration::findOrFail($json_array->db_integration_id);
     } catch (Exception $e) {
         try {
             Node::where('integration_id', '=', $json_array->db_integration_id)->delete();
             return $job->delete();
         } catch (Exception $e) {
         }
     }
     $user_id = $integration->user_id;
     $service_provider->db_integration_id = $integration->id;
     $nodes = null;
     $service_provider_nodes = array();
     foreach ($service_provider->availability_zones as $availability_zone_name => $availability_zone_friendly_name) {
         // I think this could be done with a recursive array merge
         foreach ($service_provider->list_nodes($availability_zone_name, $availability_zone_friendly_name) as $availability_zone_node_list) {
             array_push($service_provider_nodes, $availability_zone_node_list);
         }
     }
     $current_nodes = $integration->nodes;
     $all_service_provider_ids = [];
     if ($service_provider_nodes && sizeof($service_provider_nodes) > 0) {
         $integration->status = "Confirmed";
         $integration->save();
         foreach ($service_provider_nodes as $service_provider_node) {
             array_push($all_service_provider_ids, $service_provider_node['service_provider_id']);
             $node = Node::firstOrNew(array('service_provider_uuid' => $service_provider_node['service_provider_id'], 'integration_id' => $integration->id));
             // Delete the node if it's been terminated
             if ($node->service_provider_status == "terminated") {
                 $node->delete();
                 continue;
             }
             $node->service_provider_status = $service_provider_node['service_provider_status'];
             $node->service_provider_uuid = $service_provider_node['service_provider_id'];
             $node->service_provider_base_image_id = $service_provider_node['service_provider_base_image_id'];
             $node->description = $service_provider_node['private_dns_name'] . " " . $service_provider_node['public_dns_name'];
             $node->owner_id = $integration->user_id;
             $node->public_dns_name = $service_provider_node['public_dns_name'];
             $node->platform = $service_provider_node['platform'];
             $node->name = "";
             try {
                 $node->service_provider_availability_zone = $service_provider_node['availability_zone_name'];
                 $node->friendly_availability_zone = $service_provider_node['availability_zone_friendly'];
             } catch (Exception $e) {
                 $node->service_provider_availability_zone = "San Francisco!";
                 $node->friendly_availability_zone = "San Francisco!";
             }
             // This should be handled in the DB schema. Default val of false.
             if ($node->managed == null) {
                 $node->managed = false;
             }
             $base_image = BaseImage::firstOrNew(array('integration_id' => $integration->id, 'service_provider_id' => $service_provider_node['service_provider_base_image_id'], 'integration_id' => $integration->id, 'service_provider_label' => $service_provider_node['service_provider_base_image_id']));
             $base_image->rollback_index = 0;
             // Should be handled by schema or just removed. Stupid.
             $base_image->save();
             $node->base_image_id = $base_image->id;
             if (!is_null($service_provider_node['service_provider_cluster_id'])) {
                 $node->service_provider_cluster_id = $service_provider_node['service_provider_cluster_id'];
             }
             $node->save();
             foreach ($service_provider_node['service_provider_ip_addresses'] as $service_provider_ip) {
                 $db_ip = IpAddress::firstOrNew(array('address' => $service_provider_ip, 'node_id' => $node->id));
                 $db_ip->save();
             }
             // Delete ips from the database that don't appear in client report
             IpAddress::where('address', '=', $integration->id)->where('node_id', '=', $node->id)->whereNotIn('address', $service_provider_node['service_provider_ip_addresses'])->delete();
         }
         // This is where we delete Nodes that no longer exist on the service provider side.
         Node::where('integration_id', '=', $integration->id)->where('owner_id', '=', $user_id)->whereNotIn('service_provider_uuid', $all_service_provider_ids)->delete();
     } else {
         if (sizeof($service_provider_nodes) == 0) {
         }
         $integration->status = "Bad";
         $integration->save();
     }
     // Do this job again in 30 seconds.
     $job->release(900);
 }