Skip to content

Commit

Permalink
[Asset] Remove import from URL (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
brusch authored May 10, 2023
1 parent f6e5571 commit a7c3858
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 91 deletions.
45 changes: 2 additions & 43 deletions public/js/pimcore/asset/tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -610,15 +610,7 @@
iconCls: "pimcore_icon_zip pimcore_icon_overlay_upload"
});
}

if (perspectiveCfg.inTreeContextMenu("asset.add.uploadFromUrl")) {
menuItems.push({
text: t("import_from_url"),
handler: this.importFromUrl.bind(this, tree, record),
iconCls: "pimcore_icon_world pimcore_icon_overlay_add"
});
}


if (menuItems.length > 0) {
menu.add(new Ext.menu.Item({
text: t('add_assets'),
Expand Down Expand Up @@ -1178,40 +1170,7 @@
console.log(e);
}
},

importFromUrl: function (tree, record) {

Ext.MessageBox.prompt(t("import_from_url"), ' ', function (button, value, object) {
if (button == "ok") {
var win = new Ext.Window({
html: t("please_wait"),
closable: false,
bodyStyle: "padding: 10px;",
modal: true
});
win.show();

Ext.Ajax.request({
url: Routing.generate('pimcore_admin_asset_importurl'),
method: 'POST',
params: {
id: record.data.id,
url: value
},
success: function () {
win.close();
pimcore.elementservice.refreshNodeAllTrees("asset", record.get("id"));

}.bind(this),
failure: function() {
win.close();
pimcore.elementservice.refreshNodeAllTrees("asset", record.get("id"));
}
});
}
}.bind(this), null, false, 'https://');
},


addAssetComplete: function (tree, record, config, file, response) {

record.data.leaf = false;
Expand Down
47 changes: 0 additions & 47 deletions src/Controller/Admin/Asset/AssetController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2351,53 +2351,6 @@ public function importZipFilesAction(Request $request, Filesystem $filesystem):
]);
}

/**
* @Route("/import-url", name="pimcore_admin_asset_importurl", methods={"POST"})
*
* @param Request $request
*
* @return JsonResponse
*
* @throws \Exception
*/
public function importUrlAction(Request $request): JsonResponse
{
$success = true;

$data = Tool::getHttpData($request->request->get('url'));
$filename = basename($request->request->get('url'));
$parentId = $request->request->getInt('id');
$parentAsset = Asset::getById($parentId);

if (!$parentAsset) {
throw $this->createNotFoundException('Parent asset not found');
}

$filename = Element\Service::getValidKey($filename, 'asset');
$filename = $this->getSafeFilename($parentAsset->getRealFullPath(), $filename);

if (empty($filename)) {
throw new \Exception('The filename of the asset is empty');
}

// check for duplicate filename
$filename = $this->getSafeFilename($parentAsset->getRealFullPath(), $filename);

if ($parentAsset->isAllowed('create')) {
$asset = Asset::create($parentId, [
'filename' => $filename,
'data' => $data,
'userOwner' => $this->getAdminUser()->getId(),
'userModification' => $this->getAdminUser()->getId(),
]);
$success = true;
} else {
Logger::debug('prevented creating asset because of missing permissions');
}

return $this->adminJson(['success' => $success]);
}

/**
* @Route("/clear-thumbnail", name="pimcore_admin_asset_clearthumbnail", methods={"POST"})
*
Expand Down
1 change: 0 additions & 1 deletion translations/admin.en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ open_document_by_id: 'Open Document'
open_asset_by_id: 'Open Asset'
open_object_by_id: 'Open Object'
element_not_found: 'Element not found'
import_from_url: 'Import from URL'
do_you_really_want_to_leave_the_editmode: 'Do you really want to leave the editmode (NO!)'
or_specify_an_asset_image_below: 'or specify an asset image below'
medium: Medium
Expand Down

0 comments on commit a7c3858

Please sign in to comment.