<commit_before>import getItemModelName from 'appkit/utils/model';
import SearchIndex from 'appkit/utils/search-index';

export default Ember.Route.extend({
  model: function (params) {
    return this.store.find('content-type', params.type_id);
  },

  actions: {
    deleteItem: function (item) {
      if (!window.confirm('Are you sure you want to remove %@?'.fmt(item.get('itemData.name')))) {
        return;
      }

      var route = this;
      var contentType = this.get('context');

      Ember.Logger.log('Attempting to delete `%@:%@`'.fmt(contentType.get('id'), item.get('id')));

      // before we destroy this item, lets remove any reverse relationships pointing to it.

      Ember.Logger.log('Checking for reverse relations to update during item deletion.');

      var relatedKey = contentType.get('id') + ' ' + item.get('id');

      // we need to make sure the relation controlType is in the store so when we filter it happens immediately
      route.store.find('control-type', 'relation').then(function () {

        var relationControls = contentType.get('controls').filterBy('controlType.widget', 'relation');

        Ember.Logger.log('Found %@ relation control(s)'.fmt(relationControls.get('length')));

        relationControls.forEach(function (control) {

          Ember.Logger.log('Updating reverse relations of `%@`'.fmt(control.get('name')));

          var relatedContentTypeId = control.get('meta.contentTypeId');
          var relatedControlName = control.get('meta.reverseName');
          var relatedItemIds = (item.get('itemData')[control.get('name')] || []).map(function (value) {
            return value.split(' ')[1];
          });

          Ember.Logger.log('`%@` IDs %@ need to be updated'.fmt(relatedContentTypeId, relatedItemIds.join(', ')));

          // We have to get the contentType to get the itemModel.
          route.store.find('content-type', relatedContentTypeId).then(function (relatedContentType) {<commit_msg>skip content types that do not have items to update.<commit_after>import getItemModelName from 'appkit/utils/model';
import SearchIndex from 'appkit/utils/search-index';

export default Ember.Route.extend({
  model: function (params) {
    return this.store.find('content-type', params.type_id);
  },

  actions: {
    deleteItem: function (item) {
      if (!window.confirm('Are you sure you want to remove %@?'.fmt(item.get('itemData.name')))) {
        return;
      }

      var route = this;
      var contentType = this.get('context');

      Ember.Logger.log('Attempting to delete `%@:%@`'.fmt(contentType.get('id'), item.get('id')));

      // before we destroy this item, lets remove any reverse relationships pointing to it.

      Ember.Logger.log('Checking for reverse relations to update during item deletion.');

      var relatedKey = contentType.get('id') + ' ' + item.get('id');

      // we need to make sure the relation controlType is in the store so when we filter it happens immediately
      route.store.find('control-type', 'relation').then(function () {

        var relationControls = contentType.get('controls').filterBy('controlType.widget', 'relation');

        Ember.Logger.log('Found %@ relation control(s)'.fmt(relationControls.get('length')));

        relationControls.forEach(function (control) {

          Ember.Logger.log('Updating reverse relations of `%@`'.fmt(control.get('name')));

          var relatedContentTypeId = control.get('meta.contentTypeId');
          var relatedControlName = control.get('meta.reverseName');
          var relatedItemIds = (item.get('itemData')[control.get('name')] || []).map(function (value) {
            return value.split(' ')[1];
          });

          if (Ember.isEmpty(relatedItemIds)) {
            Ember.Logger.log('`%@` has no items to update.'.fmt(relatedContentTypeId));
            return;
          }

          Ember.Logger.log('`%@` items %@ need to be updated'.fmt(relatedContentTypeId, relatedItemIds.join(', ')));

          // We have to get the contentType to get the itemModel.
          route.store.find('content-type', relatedContentTypeId).then(function (relatedContentType) {
{'fraction_non_alphanumeric': 0.14757656136966482, 'fraction_numerical': 0.0004822763443453099, 'mean_word_length': 3.311850311850312, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1050864', 'n_tokens_mistral': 1180, 'n_tokens_neox': 1147, 'n_words': 292}