Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Asset] Remove import from URL #15

Merged
merged 2 commits into from
May 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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