Exemple #1
0
 /**
  * Sets up the default units
  * @throws \Exception
  */
 public function setupUnits()
 {
     $count = 0;
     $skipped = 0;
     $data = Setup::loadYAML(self::UNIT_DATA_FILE);
     $aUnits = array();
     foreach ($data as $unitName => $unitData) {
         if (UnitManager::getInstance()->unitExists($unitName)) {
             $skipped++;
             continue;
         }
         $unit = new Unit();
         $unit->setName($unitName);
         $unit->setSymbol($unitData["symbol"]);
         if (array_key_exists("prefixes", $unitData)) {
             if (!is_array($unitData["prefixes"])) {
                 throw new \Exception($unitName . " doesn't contain a prefix list, or the prefix list is not an array.");
             }
             foreach ($unitData["prefixes"] as $prefix) {
                 $siPrefix = SiPrefixManager::getInstance()->getSiPrefixBySymbol($prefix);
                 if ($siPrefix === false) {
                     throw new \Exception("Unable to find prefix " . $prefix);
                 }
                 $unit->getPrefixes()->add($siPrefix);
             }
         }
         PartKeepr::getEM()->persist($unit);
         $count++;
     }
     $this->entityManager->flush();
     $this->logMessage(sprintf("Imported %d Units, skipped %d because they already exist", $count, $skipped));
 }
 /**
  * Sets up the manufacturers using the YAML file.
  * @param $yaml string The path to the manufacturers YAML file
  */
 public function setupManufacturers()
 {
     $count = 0;
     $skipped = 0;
     $data = Setup::loadYAML(self::MANUFACTURER_FILE);
     foreach ($data as $mfgname => $logos) {
         try {
             ManufacturerManager::getInstance()->getManufacturerByName($mfgname);
             $skipped++;
         } catch (\Exception $e) {
             $manufacturer = new Manufacturer();
             $manufacturer->setName($mfgname);
             $this->entityManager->persist($manufacturer);
             foreach ($logos as $logo) {
                 $mfglogo = new ManufacturerICLogo();
                 $mfglogo->setManufacturer($manufacturer);
                 $mfglogo->replace(self::MANUFACTURER_PATH . "images/" . $logo);
                 $mfglogo->setOriginalFilename($logo);
                 $this->entityManager->persist($mfglogo);
             }
             $count++;
         }
     }
     $this->entityManager->flush();
     $this->logMessage(sprintf("Imported %d Manufacturers, skipped %d because they already exist", $count, $skipped));
 }
 /**
  * Imports the footprints
  * @throws \Exception
  */
 public function importFootprintData()
 {
     $count = 0;
     $skipped = 0;
     /* Import pre-defined footprints */
     $data = Setup::loadYAML(self::FOOTPRINT_FILE);
     foreach ($data as $footprintName => $footprintData) {
         /* Check if the footprint with the name already exists. If yes, skip the import for the single footprint */
         if ($this->footprintExists($footprintName)) {
             $skipped++;
             continue;
         }
         $footprint = new Footprint();
         $footprint->setName($footprintName);
         if (array_key_exists("description", $footprintData)) {
             $footprint->setDescription($footprintData["description"]);
         }
         if (array_key_exists("category", $footprintData)) {
             $footprintCategory = $this->addFootprintPath(explode("/", $footprintData["category"]), FootprintCategoryManager::getInstance()->getRootNode());
             $footprint->setCategory($footprintCategory->getNode());
         }
         if (array_key_exists("image", $footprintData)) {
             $footprintImage = new FootprintImage();
             $footprintImage->setFootprint($footprint);
             $footprintImage->replace(self::FOOTPRINT_PATH . $footprintData["image"]);
             $footprint->setImage($footprintImage);
         }
         if (array_key_exists("attachments", $footprintData) && is_array($footprintData["attachments"])) {
             foreach ($footprintData["attachments"] as $attachment) {
                 if (!is_array($attachment)) {
                     throw new \Exception("Error: The property 'attachments' of {$footprintName} is not an array!");
                 }
                 if (array_key_exists("url", $attachment)) {
                     try {
                         $footprintAttachment = new FootprintAttachment();
                         $footprintAttachment->setFootprint($footprint);
                         $footprintAttachment->replaceFromURL($attachment["url"]);
                         if (array_key_exists("description", $attachment)) {
                             $footprintAttachment->setDescription($attachment["description"]);
                         }
                         $footprint->getAttachments()->add($footprintAttachment);
                     } catch (\Exception $e) {
                         //echo "error with url ".$attachment["url"]."\n";
                     }
                 }
             }
         }
         $this->entityManager->persist($footprint);
         $count++;
     }
     $this->entityManager->flush();
     $this->logMessage(sprintf("Imported %d footprints, skipped %d because they already existed", $count, $skipped));
 }
 /**
  * Sets up the SI prefixes
  */
 public function setupSiPrefixes()
 {
     $count = 0;
     $skipped = 0;
     $data = Setup::loadYAML(self::SIPREFIX_DATA_FILE);
     foreach ($data as $prefixName => $prefixData) {
         if (!SiPrefixManager::getInstance()->siPrefixExists($prefixName)) {
             $prefix = new SiPrefix();
             $prefix->setPrefix($prefixName);
             $prefix->setPower($prefixData["power"]);
             $prefix->setSymbol($prefixData["symbol"]);
             $this->entityManager->persist($prefix);
             $count++;
         } else {
             $skipped++;
         }
     }
     $this->entityManager->flush();
     $this->logMessage(sprintf("Imported %d Si Prefixes, skipped %d", $count, $skipped));
 }
PartKeepr::initializeClassLoaders();
$config = new \Doctrine\DBAL\Configuration();
/**
 * Test if the requested driver is available
 */
$drivers = PDO::getAvailableDrivers();
$bDriverAvailable = false;
if (!in_array($_REQUEST["driver"], $drivers)) {
    echo json_encode(array("error" => true, "message" => "The requested driver isn't installed as PHP pdo module. Please install the PDO driver for PHP."));
    exit;
}
/**
 * Check which driver we are going to use, and set the connection parameters accordingly.
 */
try {
    $onnectionOptions = Setup::setDatabaseConfigurationFromRequest();
    $connectionOptions = PartKeepr::createConnectionOptionsFromConfig();
} catch (\Exception $e) {
    echo json_encode(array("error" => true, "message" => $e->getMessage()));
    exit;
}
$conn = \Doctrine\DBAL\DriverManager::getConnection($connectionOptions, $config);
try {
    $conn->connect();
} catch (\PDOException $e) {
    $additionalMessage = getPlatformSpecificErrorMessage($_REQUEST["driver"], $e->getCode());
    echo json_encode(array("error" => true, "message" => "There was an error connecting to the database:<br/><code>" . $e->getMessage() . "</code>" . $additionalMessage));
    exit;
} catch (\Exception $e) {
    echo json_encode(array("error" => true, "message" => "An unknown error occured. The error is: <code>" . $e->getMessage() . "</code>"));
    exit;
            echo " --help\t\t\tDisplays this help\n\n";
            die;
            break;
    }
}
if ($ask) {
    echo "If you are sure you want to do this, type YES and hit return.\n";
    $fp = fopen('php://stdin', 'r');
    $data = fgets($fp, 1024);
    if ($data !== "YES\n") {
        echo "Aborting.\n";
        die;
    }
}
echo "Performing actions...\n";
$setup = new Setup();
$setup->setConsole();
$setup->runCLIChecks();
$setup->run();
if ($migration) {
    if (Configuration::getOption("partkeepr.migration.partdb.hostname", false) === false || Configuration::getOption("partkeepr.migration.partdb.username", false) === false || Configuration::getOption("partkeepr.migration.partdb.password", false) === false || Configuration::getOption("partkeepr.migration.partdb.dbname", false) === false) {
        echo "Error migrating from partdb: One or more configuration settings are missing.\n";
        echo "Please make sure that you define the partkeepr.migration.partdb.* keys, as shown in config.php.template\n\n";
        echo "After adjusting the keys, you can safely re-run the setup, even if you already have worked with PartKeepr.\n";
        exit;
    }
    mysql_connect(Configuration::getOption("partkeepr.migration.partdb.hostname"), Configuration::getOption("partkeepr.migration.partdb.username"), Configuration::getOption("partkeepr.migration.partdb.password"));
    mysql_query("SET CHARACTER SET UTF8");
    mysql_query("SET NAMES UTF8");
    mysql_select_db(Configuration::getOption("partkeepr.migration.partdb.dbname"));
    $migration = new PartDBMigration();
Exemple #7
0
 /**
  * Sets the verbose flag
  * @param boolean $verbose True if verbose output is wanted, false otherwise
  */
 public static function setVerbose($verbose)
 {
     Setup::$verbose = $verbose;
 }
Exemple #8
0
<?php

namespace PartKeepr\Setup;

use PartKeepr\PartKeepr, PartKeepr\Setup\Setup, PartKeepr\Util\SerializableException;
set_error_handler(create_function('$a, $b, $c, $d', 'throw new ErrorException($b, 0, $a, $c, $d);'), E_ALL);
include "../src/backend/PartKeepr/PartKeepr.php";
PartKeepr::initializeClassLoaders();
try {
    Setup::setDatabaseConfigurationFromRequest();
} catch (\Exception $e) {
    echo json_encode(array("error" => true, "message" => $e->getMessage()));
    exit;
}
PartKeepr::initializeDoctrine();
$setup = new Setup();
try {
    /**
     * Workaround for the footprint setup to allow long downloads pass through
     */
    if ($_REQUEST["step"] == "footprint") {
        @set_time_limit(0);
    }
    $result = $setup->runStep($_REQUEST["step"]);
    //var_dump($result);
    if ($result !== null) {
        $aResult = array_merge($result, array("error" => false));
        echo json_encode($aResult);
    } else {
        echo json_encode(array("error" => false));
    }