Ejemplo n.º 1
0
 public function testGeneratesXml()
 {
     $package = Package::create(self::$name)->setAuthor('VikiJel')->addExtension('com_test', self::$archive_src)->addLanguage(self::$ini_src)->addUpdateServer('http://example.com', 'testserver')->setScriptfile(self::$php_src);
     $instance = Xml::create($package)->init();
     $simple_xml = simplexml_load_string((string) $instance);
     self::assertEquals('extension', (string) $simple_xml->getName());
     self::assertEquals('2.5', (string) $simple_xml->attributes()->version);
     self::assertEquals('upgrade', (string) $simple_xml->attributes()->method);
     self::assertEquals('package', (string) $simple_xml->attributes()->type);
     self::assertEquals('1.0.0', (string) $simple_xml->version);
     self::assertEquals(self::$name, (string) $simple_xml->name);
     self::assertEquals('package_test', (string) $simple_xml->packagename);
     self::assertEquals(date('Y-m-d'), (string) $simple_xml->creationDate);
     self::assertEquals('http://example.com', (string) $simple_xml->updateservers->server);
     self::assertEquals('testserver', (string) $simple_xml->updateservers->server->attributes()->name);
     self::assertEquals(1, (int) $simple_xml->updateservers->server->attributes()->priority);
     self::assertEquals('extension', (string) $simple_xml->updateservers->server->attributes()->type);
     self::assertEquals('com_test', (string) $simple_xml->files->file->attributes()->id);
     self::assertEquals('some_file.zip', (string) $simple_xml->files->file);
     self::assertEquals('en-GB.pkg_package_test.ini', (string) $simple_xml->languages->language);
     self::assertEquals('en-GB', (string) $simple_xml->languages->language->attributes()->tag);
     self::assertEquals('pkg_package_test.php', (string) $simple_xml->scriptfile);
     self::assertContains('VikiJel', (string) $simple_xml->copyright);
     self::assertContains(date('Y'), (string) $simple_xml->copyright);
     self::assertContains('VikiJel', (string) $simple_xml->packager);
     self::assertContains('vikijel', (string) $simple_xml->packagerurl);
 }
Ejemplo n.º 2
0
 /**
  * Get the package ID by package name
  * @param string $packageName
  * @return int
  */
 public static function getId($packageName)
 {
     if (($package = static::fetchOne('name', $packageName)) === false) {
         $package = Package::create(array('name' => $packageName));
     }
     return $package->id;
 }
 public function run()
 {
     Package::truncate();
     $packages = [["name" => "Premium Month", "cost" => 9, "renew" => "1 month", "type" => "membership", "value" => "premium", "active" => "premium month", "trial" => "none"], ["name" => "Platinum Month", "cost" => 17, "renew" => "1 month", "type" => "membership", "value" => "platinum", "active" => "platinum month", "trial" => "none"], ["name" => "Premium Annual", "cost" => 90, "renew" => "1 year", "type" => "membership", "value" => "premium", "active" => "premium annual", "trial" => "none"], ["name" => "Platinum Annual", "cost" => 170, "renew" => "1 year", "type" => "membership", "value" => "platinum", "active" => "platinum annual", "trial" => "none"], ["name" => "1,000 Credits", "cost" => 5, "renew" => "none", "type" => "credit", "value" => "1000", "active" => "true", "trial" => "none"], ["name" => "2,500 Credits", "cost" => 10, "renew" => "none", "type" => "credit", "value" => "2500", "active" => "true", "trial" => "none"], ["name" => "5,000 Credits", "cost" => 15, "renew" => "none", "type" => "credit", "value" => "5000", "active" => "true", "trial" => "none"], ["name" => "10,000 Credits", "cost" => 20, "renew" => "none", "type" => "credit", "value" => "10000", "active" => "true", "trial" => "none"]];
     foreach ($packages as $package) {
         Package::create($package);
     }
 }
Ejemplo n.º 4
0
 /**
  * Loads a package and its products.
  *
  * @param int $package_id
  *   The package ID.
  *
  * @return \Drupal\uc_fulfillment\Package|null
  *   The Package object, or NULL if there isn't one with the given ID.
  */
 public static function load($package_id)
 {
     if (!isset(self::$packages[$package_id])) {
         $result = db_query('SELECT * FROM {uc_packages} WHERE package_id = :id', [':id' => $package_id]);
         if ($assoc = $result->fetchAssoc()) {
             $package = Package::create($assoc);
             $products = array();
             $description = '';
             $weight = 0;
             $units = \Drupal::config('uc_store.settings')->get('weight.units');
             $addresses = array();
             $result = db_query('SELECT op.order_product_id, pp.qty, pp.qty * op.weight__value AS weight, op.weight__units, op.nid, op.title, op.model, op.price, op.data FROM {uc_packaged_products} pp LEFT JOIN {uc_order_products} op ON op.order_product_id = pp.order_product_id WHERE pp.package_id = :id ORDER BY op.order_product_id', [':id' => $package->package_id]);
             foreach ($result as $product) {
                 $address = uc_quote_get_default_shipping_address($product->nid);
                 // TODO: Lodge complaint that array_unique() compares as strings.
                 if (!in_array($address, $addresses)) {
                     $addresses[] = $address;
                 }
                 $description .= ', ' . $product->qty . ' x ' . $product->model;
                 // Normalize all weights to default units.
                 $weight += $product->weight * uc_weight_conversion($product->weight__units, $units);
                 $product->data = unserialize($product->data);
                 $products[$product->order_product_id] = $product;
             }
             $package->addresses = $addresses;
             $package->description = substr($description, 2);
             $package->weight = $weight;
             $package->weight_units = $units;
             $package->products = $products;
             if ($package->label_image && ($image = file_load($package->label_image))) {
                 $package->label_image = $image;
             }
             self::$packages[$package_id] = $package;
             return $package;
         } else {
             return NULL;
         }
     }
     // Return package from cache.
     return self::$packages[$package_id];
 }
Ejemplo n.º 5
0
 public function run()
 {
     Eloquent::unguard();
     Package::create(array('package_name' => 'Package 1', 'package_price' => '135', 'package_time' => '8', 'package_description' => 'This is the first package and a description of it'));
     Package::create(array('package_name' => 'Package 2', 'package_price' => '175', 'package_time' => '2', 'package_description' => 'This is the second package and a description of it'));
 }
Ejemplo n.º 6
0
 if ($user === NULL or !$user->isadmin and $settings["repo_mode"] == "private") {
     throw new NotFoundError();
 }
 $url_now = array();
 $ste->vars["menu"] = "upload";
 $ste->vars["title"] = "Upload new package";
 if (isset($_POST["upload_package"])) {
     if (is_uploaded_file($_FILES["pkgfile"]["tmp_name"])) {
         $raw_pkg = @file_get_contents($_FILES["pkgfile"]["tmp_name"]);
         @unlink($_FILES["pkgfile"]["tmp_name"]);
         if ($raw_pkg === False) {
             $ste->vars["error"] = "Upload failed.";
         } else {
             try {
                 $newpkg = PluginPackage::load($raw_pkg);
                 $pkg = Package::create($newpkg->name, $user);
                 $pkg->newversion($newpkg);
                 $ste->vars["success"] = "Successfully uploaded new package.";
                 $url_next = array("p", $newpkg->name);
                 return;
             } catch (InvalidPackage $e) {
                 $ste->vars["error"] = "Invalid package. Reason: " . $e->getMessage();
             } catch (NotAllowedError $e) {
                 $ste->vars["error"] = "This is not allowed. Reason: " . $e->getMessage();
             } catch (InvalidArgumentException $e) {
                 $ste->vars["error"] = $e->getMessage();
             } catch (AlreadyExistsError $e) {
                 $ste->vars["error"] = "A package with this name already exists.";
             }
         }
     } else {