EdisonPeM / strapi-plugin-import-export-content

Csv and Json import / export content plugin to Strapi
https://www.npmjs.com/package/strapi-plugin-import-export-content
MIT License
146 stars 66 forks source link

Export only maximum 100 entries & utf-8 characters #31

Open mazero opened 3 years ago

mazero commented 3 years ago

Hello,

We have tried your plugin, we find bugs and things that would be cool.

Then, it would be a really good idea to be able to update the existing contents (linked to the id on the new import).

carediary commented 3 years ago

I am also experiencing the same "We can import and export data but when we want to export more than 100 entries, we can't. (issue)"

JohnnyK84 commented 3 years ago

Just installed this plugin and we have the same problem for exporting. By default we are only getting 100 entries back. Anyone find a work around to fix this?

JohnnyK84 commented 3 years ago

I would say the cap of 100 in the response is due to Strapis default return _limit which is 100 by default. This can be seen in the Swagger documentation when running a get on the same API (only 100 results returned). Adjusting the _limit parameter returns more results. So I guess to fix the _limit parameter on the query which exports the data should include a _limit amount. Unfortunately I don't know where in the code to set this param.

JohnnyK84 commented 3 years ago

OK so I found where this is happening in the src code: In services/exporter/index.js

async function getData(target, options, userAbility) {
  const { uid, attributes } = target;
  const permissionsManager =
    strapi.admin.services.permission.createPermissionsManager({
      ability: userAbility,
      model: uid,
    });

  // Filter content by permissions
  const query = permissionsManager.queryFrom({}, PERMISSIONS.read);
  console.log("QUERY: ", query); // check query data before change
  query._limit = 200; // <<<<< set the return limit here
  console.log("QUERY: ", query); // check query data after change

  const items = await strapi.entityService.find(
    { params: query },
    { model: uid },
  );

  return Array.isArray(items)
    ? items.map((item) => cleanFields(item, options, attributes))
    : [cleanFields(items, options, attributes)];
}

@EdisonPeM In the code above I simply added the _limit param as a key to the object. The exporter then exported >100 rows :) Any chance a fix could be made to either:

  1. Set the limit to something like 999999
  2. Have an input that allows the user to specify the _limit amount

BTW Nice work on this plugin ❤

mazero commented 3 years ago

_limit = -1 is equal to unlimited @JohnnyK84

b-emini commented 3 years ago

@mazero Maybe you could create a merge request with your solution.

deepakrudrapaul commented 3 years ago

I have created a merge request with the solution mentioned above, It would be great if @EdisonPeM merge it.

R-Sudharsan25 commented 3 years ago

OK so I found where this is happening in the src code: In services/exporter/index.js

async function getData(target, options, userAbility) {
  const { uid, attributes } = target;
  const permissionsManager =
    strapi.admin.services.permission.createPermissionsManager({
      ability: userAbility,
      model: uid,
    });

  // Filter content by permissions
  const query = permissionsManager.queryFrom({}, PERMISSIONS.read);
  console.log("QUERY: ", query); // check query data before change
  query._limit = 200; // <<<<< set the return limit here
  console.log("QUERY: ", query); // check query data after change

  const items = await strapi.entityService.find(
    { params: query },
    { model: uid },
  );

  return Array.isArray(items)
    ? items.map((item) => cleanFields(item, options, attributes))
    : [cleanFields(items, options, attributes)];
}

@EdisonPeM In the code above I simply added the _limit param as a key to the object. The exporter then exported >100 rows :) Any chance a fix could be made to either:

  1. Set the limit to something like 999999
  2. Have an input that allows the user to specify the _limit amount

BTW Nice work on this plugin ❤

I couldn't find the file you're specifying can you check if its added as a feature because I am stuck at this point. Also should I rebuild after making the change?