In media.pages.inc, line 36, function media_preview_ajax() the callback ends by die();, it should be exit() instead. It will ensure that PHP will fire the shutdown handlers.

Plus, it would be more elegant to use the delivery callback into the menu item description instead of dying, this would ensure no page at all is rendered without doing any exit() or die().

Comments

aaron’s picture

for that matter, maybe it should follow the format at http://api.drupal.org/api/drupal/modules--file--file.module/function/fil... -- looks like things have improved in d7?

pounard’s picture

Yes that probably should be better, but it seems that you have only one controller (menu callback) to respond to all AJAX requests, and those might be all much different.

JacobSingh’s picture

Status: Active » Postponed (maintainer needs more info)

At present, I don't even see where this callback is being used :(

Using the ajax_deliver requires that this be used in conjunction with the AJAX framework AFAICT, which means anything using it expecting "normal" json will fail.

Can we just remove this if it isn't in use anywhere?

dave reid’s picture

Version: 7.x-1.0-beta3 » 7.x-2.x-dev
Assigned: Unassigned » dave reid
Status: Postponed (maintainer needs more info) » Active

I also don't see where this is being used either. I'll test removing it completely.

idflood’s picture

StatusFileSize
new1.29 KB

I've tried to find a use of this callback and didn't find anything. But I may have missed something. Here is what I've found:

1. The media_preview_ajax callback is called from media.module (line 231)

$items['media/js'] = array(
    'page callback' => 'media_preview_ajax',
    'access callback' => 'media_access',
    'access arguments' => array('view'),
    'type' => MENU_CALLBACK,
    'file' => 'includes/media.pages.inc',
  );

2. Searching the files for "media/js" didn't lead to anything so I looked for "url:" since media_preview_ajax check for a $_GET variable of this name. I've found that media.library.js makes an ajax call at line 76:

$.ajax({
    url: this.settings.getMediaUrl,
    type: 'GET',
    dataType: 'json',
    data: this.params,
    error: errorCallback,
    success: gotMedia
  });

3. getMediaUrl is referenced twice with this:
'getMediaUrl' => url('media/browser/list'),

With these results I simply deleted the menu declaration in media.module and the callback. After a drupal cache clear and some tests I haven't noticed any broken piece.

arthurf’s picture

Version: 7.x-2.x-dev » 7.x-1.x-dev
Status: Active » Needs review

I applied patch to 1.x and tested uploading and selecting from library. Both worked fine for me.

Status: Needs review » Needs work

The last submitted patch, media_remove_die-1085136-5.patch, failed testing.

ParisLiakos’s picture

Tested against 1.x everything seems to work just fine

dave reid’s picture

Status: Needs work » Needs review

Setting to re-test.

arthurf’s picture

StatusFileSize
new1.2 KB

Re-rolled patch from git

dave reid’s picture

Status: Needs review » Reviewed & tested by the community

Looks good then.

arthurf’s picture

Status: Reviewed & tested by the community » Needs work
StatusFileSize
new470 bytes

Looks like 2.x already removed media_preview_ajax() so it only needs the menu item removed. Here is a separate patch for 2.x

arthurf’s picture

Status: Needs work » Needs review
ParisLiakos’s picture

Status: Needs review » Reviewed & tested by the community

Tested on 2.x,everything still works
So we have #10 for 1.x and #12 for 2.x

aaron’s picture

from http://drupalcode.org/project/media.git/blobdiff/55a3ab29bb60cdc241fc1a3... :

 function media_menu() {
-  // AJAX formatter. This page is used to create the formatter form
-  // when adding a new file, after selecting a file and pressing 'Add'.
-  $items['media/js'] = array(
-    'page callback'    => 'media_ahah_formatter_load',
-    'access arguments' => array('access content'),

doesn't work like that anymore. kill it!

arthurf’s picture

Status: Reviewed & tested by the community » Closed (fixed)

Committed to 1.x and 2.x