/**
  * Migrates the existing footprints
  */
 public function run()
 {
     $count = 0;
     $skipped = 0;
     // Get or create node for the imported footprints
     $footprintCategory = FootprintSetup::addFootprintPath(explode("/", "Imported Footprints"), FootprintCategoryManager::getInstance()->getRootNode());
     $r = mysql_query("SELECT * FROM footprints");
     while ($sFootprint = mysql_fetch_assoc($r)) {
         $name = PartDBMigration::convertText($sFootprint["name"]);
         try {
             FootprintManager::getInstance()->getFootprintByName($name);
             $skipped++;
         } catch (\Exception $e) {
             $footprint = new Footprint();
             $footprint->setName($name);
             $footprint->setCategory($footprintCategory->getNode());
             $this->entityManager->persist($footprint);
             $count++;
         }
     }
     $this->entityManager->flush();
     $this->logMessage(sprintf("Migrated %d footprints, skipped %d because they already exist", $count, $skipped));
 }
<?php

/**
 * This is a script which updates all category path caches to the configured path separator.
 * 
 * This script needs to be called after changing the partkeepr.category.path_separator.
 */
namespace PartKeepr\Scripts;

use PartKeepr\PartKeepr, PartKeepr\PartCategory\PartCategoryManager, PartKeepr\Util\Configuration, PartKeepr\FootprintCategory\FootprintCategoryManager;
include "../src/backend/PartKeepr/PartKeepr.php";
PartKeepr::initialize();
PartCategoryManager::getInstance()->updateCategoryPaths(PartCategoryManager::getInstance()->getRootNode());
FootprintCategoryManager::getInstance()->updateCategoryPaths(FootprintCategoryManager::getInstance()->getRootNode());
PartKeepr::getEM()->flush();
echo "All categories are updated for the configured category seperator of ";
echo Configuration::getOption("partkeepr.category.path_separator") . "\n";
 /**
  * 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));
 }