Exemplo n.º 1
0
 public function verifyAndUpdatePlugins()
 {
     $plugins = Plugin::where('active', '=', 1)->get();
     // Going to compare checksums
     // for each of these plugins
     $n = 0;
     foreach ($plugins as $num => $plugin) {
         $n++;
         // Defaults not to update
         $update = false;
         // fetching via http
         $xml = @file_get_contents($plugin->xml_url);
         if (!$xml) {
             echo 'Plugin (' . $n . '/' . sizeof($plugins) . "): \"" . $plugin->name . "\" Cannot get XML file via HTTP, Skipping.\n";
             continue;
         }
         $crc = md5($xml);
         // compute crc
         if ($plugin->xml_crc != $crc || $plugin->name == NULL) {
             $update = true;
             // if we got
             // missing name or changing
             // crc, then we're going to
             // update that one
         } else {
             echo 'Plugin (' . $n . '/' . sizeof($plugins) . "): \"" . $plugin->name . "\" Already updated, Skipping.\n";
             continue;
         }
         // loading XML OO-style with simplemxl
         $xml = new ValidableXMLPluginDescription($xml);
         if (!$xml->isValid()) {
             echo 'Plugin (' . $n . '/' . sizeof($plugins) . "): \"" . $plugin->name . "\" Unreadable/Non validable XML, Skipping.\n";
             echo "Errors: \n";
             foreach ($xml->errors as $error) {
                 echo " - " . $error . "\n";
             }
             continue;
         }
         $xml = $xml->contents;
         echo 'Plugin (' . $n . '/' . sizeof($plugins) . '): Updating ... ';
         $this->updatePlugin($plugin, $xml, $crc);
     }
 }
Exemplo n.º 2
0
 }
 foreach ($fields as $prop) {
     if (!property_exists($body, $prop)) {
         return Tool::endWithJson(["error" => "Missing " . $prop]);
     }
 }
 // Quickly validating
 if (Plugin::where('xml_url', '=', $body->plugin_url)->count() > 0) {
     return Tool::endWithJson(["error" => "That plugin XML URL has already been submitted."]);
 }
 $xml = @file_get_contents($body->plugin_url);
 if (!$xml) {
     return Tool::endWithJson(["error" => "We cannot fetch that URL."]);
 }
 $xml = new ValidableXMLPluginDescription($xml);
 if (!$xml->isValid()) {
     return Tool::endWithJson(["error" => "Unreadable/Non validable XML.", "details" => $xml->errors]);
 }
 $xml = $xml->contents;
 if (Plugin::where('key', '=', $xml->key)->count() > 0) {
     return Tool::endWithJson(["error" => "Your XML describe a plugin whose key already exists in our database."]);
 }
 $plugin = new Plugin();
 $plugin->xml_url = $body->plugin_url;
 $plugin->date_added = DB::raw('NOW()');
 $plugin->active = false;
 $plugin->save();
 $msg_alerts_settings = Tool::getConfig()['msg_alerts'];
 $recipients = '';
 $i = 0;
 foreach ($msg_alerts_settings['recipients'] as $recipient) {