protected function importTerm($node, $parentKey, $uriBase) { $attrs = $node->attributes(); $id = strval($attrs->termID); if (!strlen($id)) { echo "Warning: Skipping Term with no termID\n"; return; } $uri = $uriBase . ':' . $id; echo "Asset URL is " . $uri . "\n"; $name = strval($node->Name); echo "Name is " . $name . "\n"; $defn = strval($node->Definition); echo "Definition is " . $defn . "\n"; if (!($asset = Asset::getByURL($this->db, $uri))) { $asset = Asset::create($this->db, $this->classname); echo "Created new term with key " . $asset->key . "\n"; $asset->title = $name; $asset->description = $defn; $asset->url[] = $uri; if ($parentKey) { $asset->parent = $parentKey; } $asset->commit(); } else { echo "Matched existing term with key " . $asset->key . "\n"; } foreach ($node->Term as $term) { $this->importTerm($term, $asset->key, $uriBase); } }
public function run() { $faker = Faker::create(); foreach (range(1, 10) as $index) { Asset::create([]); } }
public static function create($db, $class = '') { if ($class == '') { $class = 'video'; } return parent::create($db, $class); }
/** * Auto generated seed file * * @return void */ public function run() { \DB::table('assets')->delete(); $brands = array('Dell', 'Asus', 'Acer', 'Samsung', 'Sony', 'HP'); $rooms = DB::table('ceas_rooms')->lists('name'); $dids = DB::table('department')->lists('id'); $types = array('PC', 'Laptop', 'Monitor', 'TV', 'Server', 'Other'); $faker = Faker\Factory::create(); foreach (range(1, 25) as $id) { Asset::create(['brand_name' => $faker->randomElement($brands), 'room' => $faker->randomElement($rooms), 'active' => $faker->optional($weight = 0.4, $default = '1')->randomElement(array('0', '1')), 'mac_address' => $faker->macAddress, 'ip_address' => $faker->ipv4, 'assignee_name' => $faker->name, 'asset_type' => $faker->randomElement($types), 'department_id' => $faker->randomElement($dids), 'serial_number' => $faker->randomNumber(9), 'asset_tag' => $faker->md5, 'description' => $faker->realText(50)]); } }
public function import() { $this->asset = Asset::create($this->db, $this->classname); if (is_array($this->data)) { foreach ($this->data as $k => $v) { if (substr($k, 0, 1) == '_') { continue; } $this->asset->{$k} = $v; } } $this->asset->commit(); return $this->asset; }
protected function getOrCreateAssetFolderByPath($path) { $folder = Asset_Folder::getByPath($path); if (!$folder instanceof Asset_Folder) { str_replace("\\", "/", $path); $parts = explode("/", $path); if (empty($parts[count($parts) - 1])) { $parts = array_slice($parts, 0, -1); } $parts = array_slice($parts, 1); $parentPath = "/"; foreach ($parts as $part) { $parent = Asset_Folder::getByPath($parentPath); if ($parent instanceof Asset_Folder) { $part = Pimcore_File::getValidFilename($part); $folder = Asset_Folder::getByPath($parentPath . $part); if (!$folder instanceof Asset_Folder) { $folder = Asset::create($parent->getId(), array("filename" => $part, "type" => "folder", "userOwner" => $this->getUser()->getId(), "userModification" => $this->getUser()->getId())); } $parentPath .= $part . "/"; } else { Logger::error("parent not found!"); return null; } } } return $folder; }
/** * Creates a simple "TYPE 1" link between assets * * @param object &$parent_asset The parent asset * @param object &$child_asset The child asset * * @return int * @access public */ function createLink(Asset &$parent_asset, Asset &$child_asset) { // Link the asset to the parent asset $link = array('asset' => &$parent_asset, 'link_type' => 1, 'value' => '', 'sort_order' => NULL, 'is_dependant' => FALSE, 'is_exclusive' => FALSE); $link_id = $child_asset->create($link); return $link_id; }
/** * makes sure, that the creation of assets with duplicate paths is not possible * @expectedException Exception * @depends testAssetFolderCreate */ public function testDuplicateAssetPath() { $key = uniqid(); Asset::create(1, array("filename" => $key, "type" => "folder", "userOwner" => 1, "userModification" => 1)); Asset::create(1, array("filename" => $key, "type" => "folder", "userOwner" => 1, "userModification" => 1)); }
/** * creates a new folder in current directory * * @param string $name * @return string */ function createDirectory($name) { $asset = Asset::create($this->asset->getId(), array("filename" => Pimcore_File::getValidFilename($name), "type" => "folder")); }