Skip to content

[4.0] refactor the media adapters#34069

Merged
Fedik merged 15 commits intojoomla:4.0-devfrom
dgrammatiko:—refactor-media-adapters-4.0-dev
May 22, 2021

Hidden character warning

The head ref may contain hidden characters: "\u2014refactor-media-adapters-4.0-dev"
Merged

[4.0] refactor the media adapters#34069
Fedik merged 15 commits intojoomla:4.0-devfrom
dgrammatiko:—refactor-media-adapters-4.0-dev

Conversation

@dgrammatiko
Copy link
Contributor

@dgrammatiko dgrammatiko commented May 21, 2021

Pull Request for Issue #26750 (comment).

Summary of Changes

This is a proposal to change the adapters from ie: local-0 to ie: local-images as sated #26750 (comment).
Probably if this is ok (I think the second part would be better if it's md5($name)) would be merged to #33724 for easier testing?

@joomdonation @Fedik @bembelimen your thoughts here?

Testing Instructions

Goto: administrator/index.php?option=com_plugins&view=plugins&filters=[type=filesystem]
Edit FileSystem - Local plugin by adding a new path, eg installation
Check the media manager
Re-edit the previous plugin by changing the order of the folders (first installation, second images)
Check again the media manager still operates fine

Also, edit any article (or create a new one):

  • with tinMCE try to upload an image with drag and drop
  • try to select an image for intro or full position

Actual result BEFORE applying this Pull Request

Expected result AFTER applying this Pull Request

There shouldn't be any difference for end-users. This PR just ensures that the adapters are not index related.

Documentation Changes Required

@joomla-cms-bot joomla-cms-bot added NPM Resource Changed This Pull Request can't be tested by Patchtester PR-4.0-dev labels May 21, 2021
@dgrammatiko dgrammatiko force-pushed the —refactor-media-adapters-4.0-dev branch from 2592ca4 to 2f80acf Compare May 21, 2021 10:46
@dgrammatiko dgrammatiko force-pushed the —refactor-media-adapters-4.0-dev branch from 2f80acf to d4f173c Compare May 21, 2021 10:47
@dgrammatiko dgrammatiko marked this pull request as ready for review May 21, 2021 11:21
@richard67
Copy link
Member

@dgrammatiko The linter is still a bit unhappy: https://ci.joomla.org/joomla/joomla-cms/44184/1/21 :

/********/src/administrator/components/com_media/resources/scripts/store/state.es6.js
  13:15  error  'key' is assigned a value but never used  no-unused-vars

@dgrammatiko
Copy link
Contributor Author

@dgrammatiko The linter is still a bit unhappy

That was an easy fix but this PR is breaking B/C. (Anyways I was asked if I could help to transition from the index-based naming to this new name-based, so I guess this is already justified)

Not index based so won’t break
@Fedik
Copy link
Member

Fedik commented May 21, 2021

looks good, if it works ;)

I not remember where exactly, in past I seen places where second part of the adapter is cast to integer,
I mean stuff like:

$blabla = (int) $part[1];

@dgrammatiko
Copy link
Contributor Author

I not remember where exactly, in past I seen places where second part of the adapter is cast to integer,

A quick search returned no casting (int) results in com_media or the plugin

@Fedik
Copy link
Member

Fedik commented May 21, 2021

A quick search returned no casting

Maybe I mixed something, thanks for checking

$directoryPath = JPATH_ROOT . '/' . $directoryEntity->directory;
$directoryPath = rtrim($directoryPath) . '/';
$adapters[] = new \Joomla\Plugin\Filesystem\Local\Adapter\LocalAdapter($directoryPath, $directoryEntity->directory);
$adapters[$directoryEntity->directory] = new \Joomla\Plugin\Filesystem\Local\Adapter\LocalAdapter(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Almost there. To make it works well (hard to explain), we will have to change this block of code to:

foreach ($directories as $directoryEntity)
{
	if ($directoryEntity->directory)
	{
		$directoryPath = JPATH_ROOT . '/' . $directoryEntity->directory;
		$directoryPath = rtrim($directoryPath) . '/';

		$adapter = new \Joomla\Plugin\Filesystem\Local\Adapter\LocalAdapter(
			$directoryPath, $directoryEntity->directory
		);

		$adapters[$adapter->getAdapterName()] = $adapter;
	}
}

Now, the name of the adapters have this format: local-images, local-sampledata
images, sampledata is returned by $adapter->getAdapterName() method, so later, to allow the system to find the right adapter from path in the request, we will have to use $adapter->getAdapterName() as key name of the item.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I hope this is understandable. Hard to explain but it is still not clear, I will try to find a better way to explain. I only see this problem while checking to see why dropbox adapter does not work after this change.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

*
* @return {Array}
*/
const getDrives = (adapterNames, adapterName) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The parameters name of function here is a bit confusing. How about changing it to const getDrives = (adapterNames, provider). In the server side, we call local, dropbox as providers, so I think we should make the same change here to make it consistent.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if we need to change anything here as the object (client-side) remains the same:
Screenshot 2021-05-21 at 17 37 55

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, done, arguments renamed

@joomdonation
Copy link
Contributor

Thanks @dgrammatiko. All good. I will now run a final test.

@joomdonation
Copy link
Contributor

Sorry. Could you please do a final change https://github.com/joomla/joomla-cms/blob/4.0-dev/layouts/joomla/form/field/media.php#L107 ? Change local-0 to local-images

Later it will be changed anyway. But this is to avoid when your PR merged, people use nightly build won't get error while trying to select an image for article.

@richard67
Copy link
Member

I have tested this item ✅ successfully on 04fa696


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/34069.

@richard67 richard67 changed the title [4.0] refactor the media adapters [4.0] refactor the media adapters May 21, 2021
@richard67
Copy link
Member

RTC


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/34069.

@joomla-cms-bot joomla-cms-bot added Unit/System Tests RTC This Pull Request is Ready To Commit labels May 21, 2021
@richard67 richard67 added this to the Joomla 4.0 milestone May 21, 2021
@joomdonation
Copy link
Contributor

@rdeutz @wilsonge Could we have this PR merged ? I have an open RB PR which depends on this one and want to have it finished ASAP.

@Fedik Fedik merged commit a398191 into joomla:4.0-dev May 22, 2021
@joomla-cms-bot joomla-cms-bot removed the RTC This Pull Request is Ready To Commit label May 22, 2021
@Fedik
Copy link
Member

Fedik commented May 22, 2021

Thanks!

@dgrammatiko dgrammatiko deleted the —refactor-media-adapters-4.0-dev branch May 22, 2021 09:58
@PhilETaylor

This comment was marked as abuse.

@brianteeman
Copy link
Contributor

I got this error a few times but its gone now

image

@PhilETaylor

This comment was marked as abuse.

@dgrammatiko
Copy link
Contributor Author

There's a sessionStorage entry, so unless you do some update without killing the session then this shouldn't be a problem

@PhilETaylor

This comment was marked as abuse.

@PhilETaylor

This comment was marked as abuse.

@PhilETaylor

This comment was marked as abuse.

@PhilETaylor

This comment was marked as abuse.

@dgrammatiko
Copy link
Contributor Author

Yeah, but I think it's highly unlikely to hit all these requirements at once...

@PhilETaylor

This comment was marked as abuse.

@brianteeman
Copy link
Contributor

Highly unlikely as in two people already did

@richard67
Copy link
Member

Is there anything we can do against it?

@dgrammatiko
Copy link
Contributor Author

Is there anything we can do against it?

We could empty the sessionStorage key before the update, but it won't cover all the updade paths

@dgrammatiko
Copy link
Contributor Author

But we can ask people to log out after the update and re-login (in case they used com_media right before the update). No code needed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

NPM Resource Changed This Pull Request can't be tested by Patchtester Unit/System Tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants