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

Trigger server restart create/delete language settings manager plugin #838

Closed
forsetius opened this issue Mar 24, 2018 · 5 comments
Closed
Assignees
Labels
good first issue Good for newcomers issue: bug Issue reporting a bug severity: low If the issue only affects a very niche base of users and an easily implemented workaround can solve status: confirmed Confirmed by a Strapi Team member or multiple community members

Comments

@forsetius
Copy link
Contributor

Node.js version:
v9.9.0
npm version:
5.6.0
Strapi version:
3.0.0-alpha11.1
Operating system:
Linux Mint 18.3 Cinnamon 64-bit

Do you want to request a feature or report a bug?
Bug
What is the current behavior?
Deleting the language in Settings Manager has no long-term effect. It seems to be deleted but after refresh they are there again. Trying to add a language redirects to empty page.

If the current behavior is a bug, please provide the steps to reproduce the problem
In Admin > Settings Manager > Languages:
One by one, I delete all the languages except default (English). After each deletion given language disappears and the console produces messages like:

debug DELETE /settings-manager/configurations/languages/it_it (10 ms)
info File changed: /home/username/node/site/config/locales/it_it.json
info The server is restarting

Wait until server reloads, then refresh the page. The deleted languages are listed again. However, now their locales are it_it instead of it_IT. Looking into ./config/locales you'll find two sets of files, for example it_IT.json with {"welcome": "Benvenuto"} inside and it_it.json with {} inside.

What is the expected behavior?
When server is restarting there should be modal with rotating arrows. In other cases when server reloads it is there but not after deleting a language. Then, if I delete a language it should be deleted and not visible on the list anymore. Also, UI for adding a language should work.

@lauriejim lauriejim assigned lauriejim and soupette and unassigned lauriejim Mar 25, 2018
@lauriejim lauriejim added issue: bug Issue reporting a bug severity: low If the issue only affects a very niche base of users and an easily implemented workaround can solve status: confirmed Confirmed by a Strapi Team member or multiple community members good first issue Good for newcomers labels Mar 25, 2018
@lauriejim
Copy link
Contributor

lauriejim commented Mar 27, 2018

Yes you are right.

It's not an hard issue to fix. I think you can fix it and submit a PR.
If you have any question on how to did it, maybe @soupette can help you.

You have to trigger a server restart after delete language.

@lauriejim lauriejim changed the title Can't add a new language in Admin. Can't delete languages permanently Trigger server restart create/delete language settings manager plugin Mar 27, 2018
@forsetius
Copy link
Contributor Author

Well, I tried it but it's not enough.
In ./plugins/settings-manager/controllers/SettingsManager.js at line 149 (deleteLanguage function just before closing }) I've added:

strapi.reload();

and it triggers server restart but after refreshing the page, deleted languages are back there. It seems that somehow createLanguage function is called with its

fs.writeFileSync(filePath, '{}');

BTW: I've found another bug while trying to fix this one. It's about translation labels - I'll issue PR shortly.

@forsetius
Copy link
Contributor Author

@soupette: could you help me by suggesting what else should be done beyond calling strapi.reload()?

@lauriejim lauriejim added this to the 3.0.0-alpha.12.3 milestone Apr 19, 2018
@soupette
Copy link
Contributor

Hi @forsetius are you still working on this issue? How can I help you?

@soupette
Copy link
Contributor

Hi @forsetius. Until we released the fix you can modify this file:

Path - plugins/settings-manager/controllers/SettingsManager.js

deleteLanguage: async ctx => {
    const Service = strapi.plugins['settings-manager'].services.settingsmanager;
    const { name } = ctx.params;

    const languages = Service.getLanguages();

    if (!_.find(languages, { name })) return ctx.badRequest(null, [{ messages: [{ id: 'request.error.languages.unknow' }] }]);

    const filePath = path.join(strapi.config.appPath, 'config', 'locales', `${name}.json`);

    try {
      fs.unlinkSync(filePath);

      ctx.send({ ok: true });
      // Add this line
      strapi.reload();
    } catch (e) {
      ctx.badRequest(null, Service.formatErrors([{
        target: 'name',
        message: 'request.error.config',
        params: {
          filePath: filePath
        }
      }]));
    }
  },

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers issue: bug Issue reporting a bug severity: low If the issue only affects a very niche base of users and an easily implemented workaround can solve status: confirmed Confirmed by a Strapi Team member or multiple community members
Projects
None yet
Development

No branches or pull requests

3 participants