Jump to content

Media Manager Archive


kongondo

Recommended Posts

Hello @kongondo,

I have  added a checkbox field to the media-manager-image template but cannot choose it as a custom column.

Guess this matter is about supported field types for custom columns. Fieldtype Checkbox seems not to be supported. It is supported in normal listers, though. Would it be possible to add support?

And is there a list of the supported field types?

EDIT: If I add the field id manually to the MM settings JSON, the column appears in the image lister, but not in the Settings ASM Select

  • Like 1
Link to comment
Share on other sites

Hi @gebeer,

10 hours ago, gebeer said:

Guess this matter is about supported field types for custom columns. Fieldtype Checkbox seems not to be supported. It is supported in normal listers, though. Would it be possible to add support?

I cannot remember why I don't support it. I think it is just an oversight on my part. I will add this in the future. 

 

10 hours ago, gebeer said:

And is there a list of the supported field types?

I used to have one in the docs but I cannot find that page now. I must have deleted it by mistake! Sorry. 

10 hours ago, gebeer said:

EDIT: If I add the field id manually to the MM settings JSON, the column appears in the image lister, but not in the Settings ASM Select

Better to add 'FieldtypeCheckbox' in the array in 'MediaManagerUtilities.php' around line #1814 (in the method allowedFieldTypes()). This is where I'll add it in a future release.

  • Like 1
Link to comment
Share on other sites

9 hours ago, kongondo said:

Better to add 'FieldtypeCheckbox' in the array in 'MediaManagerUtilities.php' around line #1814 (in the method allowedFieldTypes()). This is where I'll add it in a future release.

This is working great. Thank you.

Actually I had added it to the JSON before inside a migration method for MM settings. Since MM stores it's settings not as ModuleConfigData but as custom JSON, I had to come up with a method in our migration class that keeps the settings in sync between dev and live. Just in case anybody needs this, here is what I did:

	/**
	 * apply settings to MediaManager
	 */
	private function applyMediaManagerSettings()
	{
		$path = $this->wire('config')->urls->admin . 'media-manager/';
		$selector = "template=media-manager-settings, status<" . Page::statusTrash;
		if (!$this->wire('modules')->isInstalled('PagePaths')) $selector .= ", parent={$path}";
		$settingsPage = $this->wire('pages')->get($selector);
		$settingsRaw = $settingsPage->media_manager_settings;
		$settings = wireDecodeJSON($settingsRaw);

		//allowed media types
		$settings['allowed_media'] = ['media' => [/* "audio",  */"document","image","video"]];
		// Add uploads to media library and publish them
		$settings['after'][0] = 1;
		// show filter profiles: yes
		$settings['show_filter_profiles'] = [1];
		// Display User Media: Display all Media
		$settings['user_media_only'] = [1];
		// Sort Media By: Created
		$settings['sort_media'] = [4];
		// Sort Media Order: Descending
		$settings['sort_media_order'] = [2];
		// custom columns in Media manager
		$imageFields = [];
		foreach (['products', 'clinical_applications', 'technologies', 'image_gallery'] as $field) $imageFields[] = $this->wire->fields->get($field)->id;
		$settings['custom_columns'] = array('image' => $imageFields);
		// filter profiles
		$settings['filters'] = [
			"filter-by-tags" => ["defaultSelector" => "title%=, media_manager_image.tags~=, media_manager_document.tags~=, media_manager_video.tags~=", "title" => "Filter by Tags"],
		];

		// save settings
		$settingsPage->of(false);
		$settingsPage->media_manager_settings = wireEncodeJSON($settings);
		$settingsPage->save();
	}

 

  • Like 1
Link to comment
Share on other sites

  • 1 month later...
On 11/30/2022 at 6:56 PM, gebeer said:

@kongondoIn my install (PW 3.0.200), Media Manager pages for images and documents get saved under Admin->Media Manager->Media Manager:Audio instead of Media Manager:Image and Media Manager:Document. They have the correct template media-manager-image and media-manager-document, but are under the wrong parent.

What could be the reason?

Hi, bringing this up again because I found the reason. On install of MM, the children under Admin->MediaManager got named "media-manager--image", --audio etc. No idea how this happended, though. Guess I will rename them manually. Since on upload the parent is defined by those page names, no parent is defined and all media gets saved under Media Manage:Audio.
A check in MediaManagerActions.php around  L1575  for $parent instancof NullPage or the like would be great to at least issue a warning.
Consequently the checks for duplicates on upload did not work. This is how I discovered the root cause.    

  • Like 1
Link to comment
Share on other sites

On 2/15/2023 at 4:55 PM, gebeer said:

Hi, bringing this up again because I found the reason. On install of MM, the children under Admin->MediaManager got named "media-manager--image", --audio etc. No idea how this happended, though. Guess I will rename them manually. Since on upload the parent is defined by those page names, no parent is defined and all media gets saved under Media Manage:Audio.
A check in MediaManagerActions.php around  L1575  for $parent instancof NullPage or the like would be great to at least issue a warning.
Consequently the checks for duplicates on upload did not work. This is how I discovered the root cause.    

Just to recap in case anyone else experienced this: After MM install I ended up with pages with wrong names (media-manager--audio, --document, --image, --video) under Admin->Media Manager. As a consequence all created media pages got saved under parent Admin->Media Manager->Media Manager:Audio. This also had an impact on duplicate media pages. They could not be detected. So no matter what the settings for duplicate media, all media got uploaded even if it was duplicates.

I used this code to rename pages under Admin->Media Manager to have correct names like (media-manager-audio, -document, -image, -video) and move all media pages to live under their correct parent pages:

		// FIX wrong Media Manager page names under Admin -> Media Manager and sort media pages under correct parent
		$types = ['audio', 'document', 'image', 'video'];
		// fix page names from "media-manager--$type" to "media-manager-$type"
		foreach($types as $type) {
			$pID = $this->wire->pages->getId("parent.name=media-manager, name=media-manager--{$type}");
			if($pID) {
				$this->wire->pages->get($pID)->setAndSave('name', "media-manager-{$type}");
			}
		}
		// move media pages from wrong parent media-manager-audio to correct parent "media-manager-$type"
		foreach($types as $type) {
			// get all media pages under media-manager-audio parent
			$ids = $this->wire->pages->findIDs("parent.name=media-manager-audio, media_manager_{$type}!=");
			// put them under correct parent
			if(count($ids)) {
				$parentID = $this->wire->pages->getID("parent.name=media-manager, name=media-manager-{$type}");
				if($parentID) {
					foreach($ids as $id) {
						$p = $this->wire->pages->get($id);
						$p->setAndSave('parent', $parentID);
					}
				}
			}
		}

 

  • Like 1
Link to comment
Share on other sites

@kongondo Where are messages from MM actions like uploads etc are supposed to appear in the GUI? I mean messages that are generated during executeAjax(). I can see them as JSON response in the dev tools for requests to e.g. /processwire/media-manager/ajax/ like

{
	"files": [
		{
			"name": "csm_us_ziehmvisionrfdhybridedition-usa-forweb_1080x1080px_7c9dea3ab6.jpg",
			"size": 34682
		}
	],
	"count_total": 1,
	"count_success": 1,
	"count_fail": 0,
	"message": "error",
	"notice": "Media Manager: No valid media found to add to Media Library. If replacing media, check that they are not locked.",
	"nothingAddedYet": "Nothing added yet.",
	"action": "upload",
	"currentPageID": 0,
	"mediaManagerFieldID": 0,
	"insertAndClose": 0,
	"galleryID": "",
	"notice2": "Media Manager: Some media were not added because names already in use (csm_us_ziehmvisionrfdhybridedition-usa-forweb_1080x1080px_7c9dea3ab6.jpg)."
}

But there is no message output in the GUI after upload.

153486760_2023-02-23-131656.thumb.png.df5b2de8200e78fba07399bfef5bf1b0.png

In this case a duplicate image was ignored for upload. Are these JSON responses supposed to be shown as messages in the GUI? If not, it would be awesome if they could be shown to the user.

  • Like 1
Link to comment
Share on other sites

@kongondo Pre-sale question: Does MM have a setting for overwriting existing files/images when updating? It seems like it would.

As an example let's say I have tiger.jpg and want to update the image with lion.jpg...but keep the name tiger.jpg while displaying the new lion.jpg...does that make sense 🤨

Link to comment
Share on other sites

On 2/23/2023 at 7:20 PM, Jim Bailie said:

@kongondo Pre-sale question: Does MM have a setting for overwriting existing files/images when updating? It seems like it would.

As an example let's say I have tiger.jpg and want to update the image with lion.jpg...but keep the name tiger.jpg while displaying the new lion.jpg...does that make sense 🤨

Hi @Jim Bailie,

Apologies for the delay in responding. Thanks for the interest in MM. There is a setting for what to do when an attempt is made to upload a media whose filename matches one that already exists in the Media Library. The current options are skip  / rename /  replace. This currently does not cover your use case. This is because currently the media page is automatically created (on upload) off of the file name. Hence, in your case, lion.jpg would create a new media page title Lion.

A similar request to yours has been made with respect to replacing the media in a Media Manager inputfield that stores only one image. In order to replace the media, one has to first delete the existing single media. It would be more intuitive and easier to (similar to PW) to just delete the existing media by the new one.

I am currently working on a new version of Media Manager that amongst other things will have an option to give uploaded media custom names instead of grabbing this from the file name. I can add your scenario usage to the TODO list for this next version.

  • Like 1
Link to comment
Share on other sites

On 2/15/2023 at 9:55 AM, gebeer said:

Hi, bringing this up again because I found the reason. On install of MM, the children under Admin->MediaManager got named "media-manager--image", --audio etc. No idea how this happended, though.

Great work! Thanks @gebeer. I wonder if sanitizer name has something to do with this? 

On 2/15/2023 at 9:55 AM, gebeer said:

A check in MediaManagerActions.php around  L1575  for $parent instancof NullPage or the like would be great to at least issue a warning.

Thanks for the suggestion. Noted for the next version.

On 2/23/2023 at 6:23 AM, gebeer said:

In this case a duplicate image was ignored for upload. Are these JSON responses supposed to be shown as messages in the GUI? If not, it would be awesome if they could be shown to the user.

They are meant to show after bulk actions such has publishing, deleting, etc. as well as when uploads are done via drag and drop (in single or all media pages and when uploading directly to an MM Inpufield). In my testing now, I see the notifications in the GUI (upper right) except for when uploading via drag and drop in the single or all media pages in MM. I'll look into this in the next version.

Link to comment
Share on other sites

6 minutes ago, Jim Bailie said:

Two months or less? 😜

Tight! Perhaps I could start with a soft upgrade/update that includes a hook that will allow you to retain names but not sure how this would work at the moment.

Having said that, you can achieve what you need manually (not ideal, I know)....by opening the media for editing (in MM), uploading your new image and deleting the old one. 
Save and you are done. In future I'll think of how one can drag and drop over an existing media to replace it.

Link to comment
Share on other sites

Quote

Tight! Perhaps I could start with a soft upgrade/update

Thank you! That's ok, no rush! This is a slow moving rebuild of an ancient application.

We have to be careful because once images are programmatically migrated by request to the old app, the links can never change from that point. And we have to make sure it's somewhat bullet-proof because of the non-technical skill levels of the admins.

And MM would be great for their workflow.

However, as far as pdf files go, which I'd like to have in place soon, I did find the module "Files Rename Replace" which gets me to a place where we can start testing/demo'ing

  • Like 1
Link to comment
Share on other sites

  • 1 month later...

I wonder if anyone can help. I'm writing an import script to add a few hundred pages to a site, and each page has a media-manager-image field. (It's for a staging site where I'm merging some recent content from a production site to keep it up-to-date.)

I successfully imported the pages using the native Processwire Import/Export, but the media manager fields were empty. I think this is because the page IDs are different on the production site and the staging site.

I have also successfully imported all of the media manager pages and assets to the staging site.

Is there a way I can populate the media-manager-image fields with the API? 

Thanks in advance, I've been pulling my hair out trying to achieve this! 😅

// I tried this approach, but it's not right
$existing_image_path = extract_img_path($img); // custom function to parse CSV, eg '/site/assets/files/86258/an-image-name.jpg'
$exists = wire('files')->exists($existing_image_path);
if ($exists) {
	// This doesn't work because it's not an image field
	$p->blog_images->add($existing_image_path);
}
$p->save();

// I then tried several ways like this, because the media is all on the staging site, but I couldn't find a way to query the media manager // pages successfully
$filename = extract_img_filename($img); // custom function to parse CSV, eg 'an-image-name.jpg'
$filename_query = "media_manager_image.filename=$filename";
$m = wire('pages')->find("template=media-manager-image,$filename_query");
if ($m->id > 0) {
	// This doesn't work because it's not an image field
	$p->blog_images = $m;
}
$p->save();

 

Edited by sodesign
add some example code
Link to comment
Share on other sites

Hi @sodesign,

8 hours ago, sodesign said:

script to add a few hundred pages to a site, and each page has a media-manager-image field

It is not clear to me what you mean by 'media-manager-image field'. Do you mean images in a FieldtypeMediaManager/InputfieldMediaManager field on a 'usual' ProcessWire page or are you talking about the actual image field (media_manager_image) that holds the images for media items in media manager pages  (which live in /admin/media-manager/...)?

Are the staging and production sites on the same server?

Edited by kongondo
Link to comment
Share on other sites

10 hours ago, sodesign said:

I successfully imported the pages using the native Processwire Import/Export, but the media manager fields were empty. I think this is because the page IDs are different on the production site and the staging site.

I think you are right. It sounds like the import for the media pages themselves (i.e. the media manager pages) worked. However, these were created as new pages using the template 'media-manager-image'. On the other hand, the 'usual' pages with FieldtypeMediaManager field perhaps also got their values imported. One of the values they hold is the page ID of the page where the media (in this case image) really lives. So, in the production site one value could be 1234. However, the newly created page in the staging could have been created with a page ID 5623.  This means that if by coincidence some IDs are identical between the sites, you might get MM images showing up in the wrong pages 😀.  

 

Back to your script.

You need to find a connection between production 'media manager pages' (i.e. the pages that use the template media-manager-image) and the staging usual pages media manager fields. The connection between them that has not changed is the page name of the media manager pages, i.e.

Production

MM Page

  • Title: My Awesome Image
  • Page ID: 1234
  • Name: my-awesome-image

Page with MM Field

  • A Frontend Page with a Gallery showing some MM Images in an MM Field
  • MM Field (WireArray of WireData where each WireData has a property id, i.e. $mmObject->id == 1234) [see the docs].

Staging

MM Page

  • Title: My Awesome Image
  • Page ID: 5623
  • Name: my-awesome-image

Page with MM Field

  • A Frontend Page with a Gallery showing some MM Images in an MM Field
  • MM Field (WireArray of WireData where each WireData has a property id, i.e. $mmObject->id == 1234) <- it points to the old value in the production site.

As you can see, the common things between the two sties is the name/title. 

One (rather convoluted way) to go about it is (written in browser, not tested and only quickly thought through).

  1. Get the values of the $mmObject->id in your 'new pages [the imports]', i.e., the value 1234 in our example. You could loop through each of the staging pages or just grab them all using findRaw("template=your-template",['id','mm_field']);
  2. Process the the above array to get all the 'data' values in the 'mm_field'. Keep this one one array.
  3. Use the ids you have collected in #2 and do a findRaw in the production site (implode the IDs so you get 1234|1345|4356, etc). What you want are the names, so findRaw("id=$ids,check_access=0",['id','name']);
  4. #3 Will give you the names and IDs of the MM pages in Production. Prepare these names for an OR selector string similar to what you did with $ids in #3.
  5. Use the $names selector string in #3 to find the corresponding MM pages in the staging site, i.e. findRaw("name=$names",['id','name']);
  6. You will end up with two arrays, one for production and one for staging with values $productionArray = [1234=>'my-awesome-image'] and $stagingArray = [5623 => 'my-awesome-image'].
  7. You can process this two arrays so that you end up with $processedArray = [1234 => 5623, etc]
  8. Loop through the newly imported pages in staging, loop through their MM fields and replace 1234 with 5623.

OR simply...

  1. Install ProcessDatabaseBackups in the production site
  2. Export the site usign ProcessDatabaseBackups
  3. Install ProcessDatabaseBackups in the staging site
  4. Use ProcessDatabaseBackups to backup the current DB in the staging site
  5. Import the exported db from production (#2) into the staging site using ProcessDatabaseBackups
  6. Copy the assets from production site into staging site
  7. Test
  8. Done 🙂
Link to comment
Share on other sites

That makes sense,  finding the connection between production 'media manager pages' and the staging usual pages media manager fields is where I was getting stuck trying to use a selector but your suggestion of looping through and creating the two arrays to compare is a great idea.

The only question I still have is with point 8:

9 hours ago, kongondo said:

Loop through the newly imported pages in staging, loop through their MM fields and replace 1234 with 5623.

How do I add a MM page to the MM field using the API if the field is currently empty? 

I'll be sure to check out ProcessDatabaseBackups! Can it handle individual parts of a site?

Link to comment
Share on other sites

8 hours ago, sodesign said:

I'll be sure to check out ProcessDatabaseBackups! Can it handle individual parts of a site?

You can cherry pick what tables to backup up, e.g. 'pages', 'field_body', 'field_images', 'templates', etc.

8 hours ago, sodesign said:

How do I add a MM page to the MM field using the API if the field is currently empty? 

If the MM fields are empty you need to find the connection between the production 'usual pages' with MM fields and the corresponding staging 'usual pages' with MM fields. Given that you used an import, similar to above assumptions, their titles and names will (should) be identical, but their IDs will be different. Hence:

Production

A Usual Page -> exported to staging

  • Title: My Usual Page
  • Page ID: 1450
  • Name: my-usual-page
  • mm_field (WireArray of WireData where each WireData has a property id, i.e. $mmObject->id == 1234)

Staging

A Usual Page <- imported from production

  • Title: My Usual Page
  • Page ID: 1876
  • Name: my-usual-page
  • mm_field (WireArray of WireData BUT EMPTY -> SO NO values for mm_field)

Production and Staging 'usual pages' are connected via 'names'. So...

  1. Staging: Use findRaw or Loop through imported staging pages. Save their names and IDs in an array.
  2. Staging: Prepare an OR (piped) selector string of $namesPipedSelectorString from #1
  3. Production: Use findRaw with $namesPipedSelectorString to find the ids, names and mm_fields values in the corresponding pages in production.
  4. Production: Prepare the IDs of the mm_fields in #3 as $idsOfMMPagesInMMFieldPipedSelectorString. If you use findRaw, this will be in the array column 'data'. These are the page IDs of the MM pages in production.
  5. Production: Use $idsOfMMPagesInMMFieldPipedSelectorString in a findRaw to get the names of the MM pages in production. Prepare these in an array of $namesOfMMPagesPipedSelectorString. d
  6. Staging: Use $namesOfMMPagesPipedSelectorString from #5 in a findRaw() to find the page IDs of the corresponding MM pages that were created when you imported from production. In other words, the MM pages in #5 and #6 are identical, expect for their page IDs.
  7. Production & Staging: Prepare an array that contains the names of the exported usual pages, the IDs of the imported usual pages (the ones with empty MM fields), the page IDs of the MM pages in #6.
  8. Your connection is complete. You now know the IDs of the MM pages and their corresponding usual pages where they need to be references in the MM fields.
  9. Staging: Loop through newly imported pages and use the array in #7 to populate the empty MM fields. I.e., in the loop, when you get to a page, e.g. 'my-usual-page', using the array in #7 find the page IDs of the corresponding MM pages. Use each of those to create a WireData object that you add to the WireArray mm_field. Pseudo code below (not tested):
<?php

namespace ProcessWire;

$importedUsualPages = $pages->find("your-selector");

$arrayOfConnections = [
  'my-usual-page' => [
    'id' => 1876,
    'imported_mm_pages_ids' => [2035, 2036, 2038, 2056]
  ]
];

foreach($importedUsualPages as $importedUsualPage){
  $importedUsualPage->of(false);
  $mmField = new WireArray();
  $importedMMPagesIDs = $arrayOfConnections[$importedUsualPage->name];
  foreach($importedMMPagesIDs as $importedMMPageID){
    $mmFieldItem = new WireData();
    $mmFieldItem->id = $importedMMPageID;
    $mmFieldItem->type = 3;// 1-audio; 2-document; 3-image; 4-video
    // add MM item to WireArray
    $mmField->add($mmFieldItem);
  }
  // -----
  // populate mm_field of page
  $importedUsualPage->set('mm_field', $mmField);
  $importedUsualPage->save('mm_field');
}

 

Hope this helps. Let me know how it goes.

Link to comment
Share on other sites

  • 2 weeks later...

@kongondo on multilang installs, when the title field is set to TextLanguage, MM pages that are creted for each image under Admin->Media Manager->Media Manager: image are published in the default language only. Other languages are disabled.

2095611855_2023-05-04-114911.thumb.png.a9c8f2e99247b30353fec3e460ff3d63.png

This poses a problem with $pages->find operations, e.g. 

$this->wire->pages->findIDs("template=media-manager-image, image_gallery=1, products.id={$this->id}");

this return 0 pages for non-default languages. I had to change the selector to

$this->wire->pages->findIDs("template=media-manager-image, image_gallery=1, products.id={$this->id}, include=all, status!=" . Page::statusUnpublished . ', status<' . Page::statusTrash);

in order to get results.

It might be good to have these pages published in all languages by default.

  • Like 1
Link to comment
Share on other sites

Hi, 

I need to upgrade my links and buttons so they can point not only to pages but also to any file inside media manager.
Right now links can be added two ways, in the text field using ckeditor and in button field (is assisted url).CKEditor works for me well but I have a problem with assisted url field.
When I select any media like pdf or image via assisted url it doesn't update the field with media url and console shows this error:
MediaManagerImageEditor.js:77 Uncaught TypeError: Cannot read properties of undefined (reading 'getSelection') at insertLinkMediaManager (MediaManagerImageEditor.js:77:29)

Does anyone who use Media Manager module with assisted url have the same issue?

 

Link to comment
Share on other sites

12 hours ago, gebeer said:

on multilang installs, when the title field is set to TextLanguage, MM pages that are creted for each image under Admin->Media Manager->Media Manager: image are published in the default language only. Other languages are disabled.

Thanks for reporting @gebeer. Added to my TODO.

  • Like 1
Link to comment
Share on other sites

  • Grzegorz changed the title to Media Manager links
  • kongondo changed the title to Media Manager Archive
  • kongondo pinned and locked this topic
Guest
This topic is now closed to further replies.
×
×
  • Create New...