View | Details | Raw Unified | Return to bug 23019
Collapse All | Expand All

(-)a/C4/ImportBatch.pm (-4 / +6 lines)
Lines 265-271 sub GetImportBatch { Link Here
265
    my ($batch_id) = @_;
265
    my ($batch_id) = @_;
266
266
267
    my $dbh = C4::Context->dbh;
267
    my $dbh = C4::Context->dbh;
268
    my $sth = $dbh->prepare_cached("SELECT * FROM import_batches WHERE import_batch_id = ?");
268
    my $sth = $dbh->prepare_cached("SELECT b.*, p.name as profile FROM import_batches b LEFT JOIN import_batches_profile p ON p.id = b.profile_id WHERE import_batch_id = ?");
269
    $sth->bind_param(1, $batch_id);
269
    $sth->bind_param(1, $batch_id);
270
    $sth->execute();
270
    $sth->execute();
271
    my $result = $sth->fetchrow_hashref;
271
    my $result = $sth->fetchrow_hashref;
Lines 1023-1031 sub GetImportBatchRangeDesc { Link Here
1023
    my ($offset, $results_per_group) = @_;
1023
    my ($offset, $results_per_group) = @_;
1024
1024
1025
    my $dbh = C4::Context->dbh;
1025
    my $dbh = C4::Context->dbh;
1026
    my $query = "SELECT * FROM import_batches
1026
    my $query = "SELECT b.*, p.name as profile FROM import_batches b
1027
                                    WHERE batch_type IN ('batch', 'webservice')
1027
                                    LEFT JOIN import_batches_profile p
1028
                                    ORDER BY import_batch_id DESC";
1028
                                    ON b.profile_id = p.id
1029
                                    WHERE b.batch_type IN ('batch', 'webservice')
1030
                                    ORDER BY b.import_batch_id DESC";
1029
    my @params;
1031
    my @params;
1030
    if ($results_per_group){
1032
    if ($results_per_group){
1031
        $query .= " LIMIT ?";
1033
        $query .= " LIMIT ?";
(-)a/Koha/ImportBatch.pm (+41 lines)
Line 0 Link Here
1
package Koha::ImportBatch;
2
3
# This file is part of Koha.
4
#
5
# Copyright 2020 Koha Development Team
6
#
7
# Koha is free software; you can redistribute it and/or modify
8
# it under the terms of the GNU General Public License as
9
# published by the Free Software Foundation; either version 3
10
# of the License, or (at your option) any later version.
11
#
12
# Koha is distributed in the hope that it will be useful, but
13
# WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
16
#
17
# You should have received a copy of the GNU General
18
# Public License along with Koha; if not, see
19
# <http://www.gnu.org/licenses>
20
21
use Modern::Perl;
22
23
use base qw(Koha::Object);
24
25
=head1 NAME
26
27
Koha::ImportBatch - Koha ImportBatch Object class
28
29
=head1 API
30
31
=head2 Class Methods
32
33
=head3 _type
34
35
=cut
36
37
sub _type {
38
    return 'ImportBatch';
39
}
40
41
1;
(-)a/Koha/ImportBatchProfile.pm (+54 lines)
Line 0 Link Here
1
package Koha::ImportBatchProfile;
2
3
# This file is part of Koha.
4
#
5
# Copyright 2020 Koha Development Team
6
#
7
# Koha is free software; you can redistribute it and/or modify
8
# it under the terms of the GNU General Public License as
9
# published by the Free Software Foundation; either version 3
10
# of the License, or (at your option) any later version.
11
#
12
# Koha is distributed in the hope that it will be useful, but
13
# WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
16
#
17
# You should have received a copy of the GNU General
18
# Public License along with Koha; if not, see
19
# <http://www.gnu.org/licenses>
20
21
use Modern::Perl;
22
23
use base qw(Koha::Object);
24
25
=head1 NAME
26
27
Koha::ImportBatchProfile - Koha ImportBatchProfile Object class
28
29
=head1 API
30
31
=head2 Class Methods
32
33
=head3 to_api_mapping
34
35
This method returns the mapping for representing a Koha::ImportBatchProfile object
36
on the API.
37
38
=cut
39
40
sub to_api_mapping {
41
    return {
42
        id => 'profile_id'
43
    };
44
}
45
46
=head3 _type
47
48
=cut
49
50
sub _type {
51
    return 'ImportBatchesProfile';
52
}
53
54
1;
(-)a/Koha/ImportBatchProfiles.pm (+51 lines)
Line 0 Link Here
1
package Koha::ImportBatchProfiles;
2
3
# This file is part of Koha.
4
#
5
# Copyright 2020 Koha Development Team
6
#
7
# Koha is free software; you can redistribute it and/or modify
8
# it under the terms of the GNU General Public License as
9
# published by the Free Software Foundation; either version 3
10
# of the License, or (at your option) any later version.
11
#
12
# Koha is distributed in the hope that it will be useful, but
13
# WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
16
#
17
# You should have received a copy of the GNU General
18
# Public License along with Koha; if not, see
19
# <http://www.gnu.org/licenses>
20
21
use Modern::Perl;
22
23
use base qw(Koha::Objects);
24
25
use Koha::ImportBatchProfile;
26
27
=head1 NAME
28
29
Koha::ImportBatchProfiles - Koha ImportBatchProfiles Object class
30
31
=head1 API
32
33
=head2 Class Methods
34
35
=head3 _type
36
37
=cut
38
39
sub _type {
40
    return 'ImportBatchesProfile';
41
}
42
43
=head3 object_class
44
45
=cut
46
47
sub object_class {
48
    return 'Koha::ImportBatchProfile';
49
}
50
51
1;
(-)a/Koha/ImportBatches.pm (+51 lines)
Line 0 Link Here
1
package Koha::ImportBatches;
2
3
# This file is part of Koha.
4
#
5
# Copyright 2020 Koha Development Team
6
#
7
# Koha is free software; you can redistribute it and/or modify
8
# it under the terms of the GNU General Public License as
9
# published by the Free Software Foundation; either version 3
10
# of the License, or (at your option) any later version.
11
#
12
# Koha is distributed in the hope that it will be useful, but
13
# WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
16
#
17
# You should have received a copy of the GNU General
18
# Public License along with Koha; if not, see
19
# <http://www.gnu.org/licenses>
20
21
use Modern::Perl;
22
23
use base qw(Koha::Objects);
24
25
use Koha::ImportBatch;
26
27
=head1 NAME
28
29
Koha::ImportBatches - Koha ImportBatches Object class
30
31
=head1 API
32
33
=head2 Class Methods
34
35
=head3 _type
36
37
=cut
38
39
sub _type {
40
    return 'ImportBatch';
41
}
42
43
=head3 object_class
44
45
=cut
46
47
sub object_class {
48
    return 'Koha::ImportBatch';
49
}
50
51
1;
(-)a/Koha/REST/V1/ImportBatchProfiles.pm (+145 lines)
Line 0 Link Here
1
package Koha::REST::V1::ImportBatchProfiles;
2
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it
6
# under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 3 of the License, or
8
# (at your option) any later version.
9
#
10
# Koha is distributed in the hope that it will be useful, but
11
# WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License
16
# along with Koha; if not, see <http://www.gnu.org/licenses>.
17
18
use Modern::Perl;
19
20
use Mojo::Base 'Mojolicious::Controller';
21
22
use Koha::ImportBatchProfiles;
23
use Koha::ImportBatchProfile;
24
25
use Try::Tiny;
26
27
=head1 NAME
28
29
Koha::REST::V1::ImportBatchProfiles - Koha REST API for handling profiles for import batches (V1)
30
31
=head1 API
32
33
=head2 Methods
34
35
=cut
36
37
=head3 list
38
39
Method that handles listing Koha::ImportBatchProfile objects
40
41
=cut
42
43
sub list {
44
    my $c = shift->openapi->valid_input or return;
45
46
    return try {
47
        my $profiles_set = Koha::ImportBatchProfiles->new;
48
        my $profiles = $c->objects->search( $profiles_set );
49
        return $c->render(
50
            status => 200,
51
            openapi => $profiles
52
        );
53
    }
54
    catch {
55
        $c->unhandled_exception($_);
56
    };
57
}
58
59
=head3 add
60
61
Method that handles adding a new Koha::ImportBatchProfile object
62
63
=cut
64
65
sub add {
66
    my $c = shift->openapi->valid_input or return;
67
68
    my $body = $c->validation->param('body');
69
70
    $body =
71
72
    return try {
73
        my $profile = Koha::ImportBatchProfile->new_from_api( $body )->store;
74
        return $c->render(
75
            status  => 201,
76
            openapi => $profile->to_api
77
        );
78
    }
79
    catch {
80
        $c->unhandled_exception($_);
81
    };
82
}
83
84
=head3 edit
85
86
Method that handles modifying a Koha::Hold object
87
88
=cut
89
90
sub edit {
91
    my $c = shift->openapi->valid_input or return;
92
93
    return try {
94
        my $profile_id = $c->validation->param('profile_id');
95
        my $profile = Koha::ImportBatchProfiles->find( $profile_id );
96
        unless ($profile) {
97
            return $c->render( status  => 404,
98
                            openapi => {error => "Import batch profile not found"} );
99
        }
100
101
        my $body = $c->req->json;
102
103
        $profile->set_from_api($body)->store;
104
105
        return $c->render(
106
            status => 200,
107
            openapi => $profile->to_api
108
        );
109
    }
110
    catch {
111
        $c->unhandled_exception($_);
112
    };
113
}
114
115
=head3 delete
116
117
Method that handles deleting a Koha::ImportBatchProfile object
118
119
=cut
120
121
sub delete {
122
    my $c = shift->openapi->valid_input or return;
123
124
    my $profile_id = $c->validation->param('profile_id');
125
    my $profile = Koha::ImportBatchProfiles->find( $profile_id );
126
127
    unless ($profile) {
128
        return $c->render( status  => 404,
129
                        openapi => {error => "Import batch profile not found"} );
130
    }
131
132
    return try {
133
        $profile->delete;
134
135
        return $c->render(
136
            status => 204,
137
            openapi => q{}
138
        );
139
    }
140
    catch {
141
        $c->unhandled_exception($_);
142
    };
143
}
144
145
1;
(-)a/api/v1/swagger/definitions.json (+6 lines)
Lines 38-43 Link Here
38
  "ill_backend": {
38
  "ill_backend": {
39
    "$ref": "definitions/ill_backend.json"
39
    "$ref": "definitions/ill_backend.json"
40
  },
40
  },
41
  "import-batch-profile": {
42
    "$ref": "definitions/import-batch-profile.json"
43
  },
44
  "import-batch-profiles": {
45
    "$ref": "definitions/import-batch-profiles.json"
46
  },
41
  "library": {
47
  "library": {
42
    "$ref": "definitions/library.json"
48
    "$ref": "definitions/library.json"
43
  },
49
  },
(-)a/api/v1/swagger/definitions/import-batch-profile.json (+53 lines)
Line 0 Link Here
1
{
2
  "type": "object",
3
  "properties": {
4
    "id_profile": {
5
      "type": "integer",
6
      "description": "Internal profile identifier"
7
    },
8
    "name": {
9
      "description": "name of this profile",
10
      "type": "string"
11
    },
12
    "matcher_id": {
13
      "description": "the id of the match rule used (matchpoints.matcher_id)",
14
      "type": ["integer", "null"]
15
    },
16
    "template_id": {
17
      "description": "the id of the marc modification template",
18
      "type": ["integer", "null"]
19
    },
20
    "overlay_action": {
21
      "description": "how to handle duplicate records",
22
      "type": ["string", "null"]
23
    },
24
    "nomatch_action": {
25
      "description": "how to handle records where no match is found",
26
      "type": ["string", "null"]
27
    },
28
    "item_action": {
29
      "description": "what to do with item records",
30
      "type": ["string", "null"]
31
    },
32
    "parse_items": {
33
      "description": "should items be parsed",
34
      "type": ["boolean", "null"]
35
    },
36
    "record_type": {
37
      "description": "type of record in the batch",
38
      "type": ["string", "null"]
39
    },
40
    "encoding": {
41
      "description": "file encoding",
42
      "type": ["string", "null"]
43
    },
44
    "format": {
45
      "description": "marc format",
46
      "type": ["string", "null"]
47
    },
48
    "comments": {
49
      "description": "any comments added when the file was uploaded",
50
      "type": ["string", "null"]
51
    }
52
  }
53
}
(-)a/api/v1/swagger/definitions/import-batch-profiles.json (+6 lines)
Line 0 Link Here
1
{
2
    "type": "array",
3
    "items": {
4
      "$ref": "import-batch-profile.json"
5
    }
6
  }
(-)a/api/v1/swagger/parameters.json (+3 lines)
Lines 11-16 Link Here
11
  "patron_id_qp": {
11
  "patron_id_qp": {
12
    "$ref": "parameters/patron.json#/patron_id_qp"
12
    "$ref": "parameters/patron.json#/patron_id_qp"
13
  },
13
  },
14
  "profile_id_pp": {
15
    "$ref": "parameters/import-batch-profile.json#/profile_id_pp"
16
  },
14
  "city_id_pp": {
17
  "city_id_pp": {
15
    "$ref": "parameters/city.json#/city_id_pp"
18
    "$ref": "parameters/city.json#/city_id_pp"
16
  },
19
  },
(-)a/api/v1/swagger/parameters/import-batch-profile.json (+9 lines)
Line 0 Link Here
1
{
2
  "profile_id_pp": {
3
    "name": "profile_id",
4
    "in": "path",
5
    "description": "Internal profile identifier",
6
    "required": true,
7
    "type": "integer"
8
  }
9
}
(-)a/api/v1/swagger/paths.json (+6 lines)
Lines 110-115 Link Here
110
  "/illrequests": {
110
  "/illrequests": {
111
    "$ref": "paths/illrequests.json#/~1illrequests"
111
    "$ref": "paths/illrequests.json#/~1illrequests"
112
  },
112
  },
113
  "/import-batch-profiles": {
114
    "$ref": "paths/import-batch-profiles.json#/~1import-batch-profiles"
115
  },
116
  "/import-batch-profiles/{profile_id}": {
117
    "$ref": "paths/import-batch-profiles.json#/~1import-batch-profiles~1{profile_id}"
118
  },
113
  "/rotas/{rota_id}/stages/{stage_id}/position": {
119
  "/rotas/{rota_id}/stages/{stage_id}/position": {
114
    "$ref": "paths/rotas.json#/~1rotas~1{rota_id}~1stages~1{stage_id}~1position"
120
    "$ref": "paths/rotas.json#/~1rotas~1{rota_id}~1stages~1{stage_id}~1position"
115
  },
121
  },
(-)a/api/v1/swagger/paths/import-batch-profiles.json (+360 lines)
Line 0 Link Here
1
{
2
  "/import-batch-profiles": {
3
    "get": {
4
      "x-mojo-to": "ImportBatchProfiles#list",
5
      "operationId": "listImportBatchProfiles",
6
      "tags": [
7
        "ImportBatchProfiles"
8
      ],
9
      "parameters": [
10
        {
11
          "name": "name",
12
          "in": "query",
13
          "description": "Search on profile's name",
14
          "required": false,
15
          "type": "string"
16
        },
17
        {
18
          "$ref": "../parameters.json#/match"
19
        },
20
        {
21
          "$ref": "../parameters.json#/order_by"
22
        },
23
        {
24
          "$ref": "../parameters.json#/page"
25
        },
26
        {
27
          "$ref": "../parameters.json#/per_page"
28
        }
29
      ],
30
      "consumes": [
31
        "application/json"
32
      ],
33
      "produces": [
34
        "application/json"
35
      ],
36
      "responses": {
37
        "200": {
38
          "description": "A list of import batch profiles",
39
          "schema": {
40
            "$ref": "../definitions.json#/import-batch-profiles"
41
          }
42
        },
43
        "401": {
44
          "description": "Authentication required",
45
          "schema": {
46
            "$ref": "../definitions.json#/error"
47
          }
48
        },
49
        "403": {
50
          "description": "Access forbidden",
51
          "schema": {
52
            "$ref": "../definitions.json#/error"
53
          }
54
        },
55
        "500": {
56
          "description": "Internal server error",
57
          "schema": {
58
            "$ref": "../definitions.json#/error"
59
          }
60
        },
61
        "503": {
62
          "description": "Under maintenance",
63
          "schema": {
64
            "$ref": "../definitions.json#/error"
65
          }
66
        }
67
      },
68
      "x-koha-authorization": {
69
        "permissions": {
70
          "catalogue": "1"
71
        }
72
      }
73
    },
74
    "post": {
75
      "x-mojo-to": "ImportBatchProfiles#add",
76
      "operationId": "addImportBatchProfiles",
77
      "tags": [
78
        "ImportBatchProfiles"
79
      ],
80
      "parameters": [
81
        {
82
          "name": "body",
83
          "in": "body",
84
          "description": "A JSON object containing a import batch profile",
85
          "required": true,
86
          "schema": {
87
            "type": "object",
88
            "properties": {
89
              "name": {
90
                "description": "name of this profile",
91
                "type": "string"
92
              },
93
              "matcher_id": {
94
                "description": "the id of the match rule used (matchpoints.matcher_id)",
95
                "type": ["integer", "null"]
96
              },
97
              "template_id": {
98
                "description": "the id of the marc modification template",
99
                "type": ["integer", "null"]
100
              },
101
              "overlay_action": {
102
                "description": "how to handle duplicate records",
103
                "type": ["string", "null"]
104
              },
105
              "nomatch_action": {
106
                "description": "how to handle records where no match is found",
107
                "type": ["string", "null"]
108
              },
109
              "item_action": {
110
                "description": "what to do with item records",
111
                "type": ["string", "null"]
112
              },
113
              "parse_items": {
114
                "description": "should items be parsed",
115
                "type": ["boolean", "null"]
116
              },
117
              "record_type": {
118
                "description": "type of record in the batch",
119
                "type": ["string", "null"]
120
              },
121
              "encoding": {
122
                "description": "file encoding",
123
                "type": ["string", "null"]
124
              },
125
              "format": {
126
                "description": "marc format",
127
                "type": ["string", "null"]
128
              },
129
              "comments": {
130
                "description": "any comments added when the file was uploaded",
131
                "type": ["string", "null"]
132
              }
133
            }
134
          }
135
        }
136
      ],
137
      "consumes": ["application/json"],
138
      "produces": ["application/json"],
139
      "responses": {
140
        "201": {
141
          "description": "Created Profile",
142
          "schema": {
143
            "$ref": "../definitions.json#/import-batch-profile"
144
          }
145
        },
146
        "400": {
147
          "description": "Missing or wrong parameters",
148
          "schema": {
149
            "$ref": "../definitions.json#/error"
150
          }
151
        },
152
        "401": {
153
          "description": "Authentication required",
154
          "schema": {
155
            "$ref": "../definitions.json#/error"
156
          }
157
        },
158
        "403": {
159
          "description": "Hold not allowed",
160
          "schema": {
161
            "$ref": "../definitions.json#/error"
162
          }
163
        },
164
        "404": {
165
          "description": "Borrower not found",
166
          "schema": {
167
            "$ref": "../definitions.json#/error"
168
          }
169
        },
170
        "500": {
171
          "description": "Internal server error",
172
          "schema": {
173
            "$ref": "../definitions.json#/error"
174
          }
175
        },
176
        "503": {
177
          "description": "Under maintenance",
178
          "schema": {
179
            "$ref": "../definitions.json#/error"
180
          }
181
        }
182
      },
183
      "x-koha-authorization": {
184
        "permissions": {
185
          "catalogue": "1"
186
        }
187
      }
188
    }
189
  },
190
  "/import-batch-profiles/{profile_id}": {
191
    "put": {
192
      "x-mojo-to": "ImportBatchProfiles#edit",
193
      "operationId": "editImportBatchProfiles",
194
      "tags": [
195
        "ImportBatchProfiles"
196
      ],
197
      "parameters": [
198
        {
199
          "$ref": "../parameters.json#/profile_id_pp"
200
        },
201
        {
202
          "name": "body",
203
          "in": "body",
204
          "description": "A JSON object containing a import batch profile",
205
          "required": true,
206
          "schema": {
207
            "type": "object",
208
            "properties": {
209
              "name": {
210
                "description": "name of this profile",
211
                "type": "string"
212
              },
213
              "matcher_id": {
214
                "description": "the id of the match rule used (matchpoints.matcher_id)",
215
                "type": ["integer", "null"]
216
              },
217
              "template_id": {
218
                "description": "the id of the marc modification template",
219
                "type": ["integer", "null"]
220
              },
221
              "overlay_action": {
222
                "description": "how to handle duplicate records",
223
                "type": ["string", "null"]
224
              },
225
              "nomatch_action": {
226
                "description": "how to handle records where no match is found",
227
                "type": ["string", "null"]
228
              },
229
              "item_action": {
230
                "description": "what to do with item records",
231
                "type": ["string", "null"]
232
              },
233
              "parse_items": {
234
                "description": "should items be parsed",
235
                "type": ["boolean", "null"]
236
              },
237
              "record_type": {
238
                "description": "type of record in the batch",
239
                "type": ["string", "null"]
240
              },
241
              "encoding": {
242
                "description": "file encoding",
243
                "type": ["string", "null"]
244
              },
245
              "format": {
246
                "description": "marc format",
247
                "type": ["string", "null"]
248
              },
249
              "comments": {
250
                "description": "any comments added when the file was uploaded",
251
                "type": ["string", "null"]
252
              }
253
            }
254
          }
255
        }
256
      ],
257
      "consumes": ["application/json"],
258
      "produces": ["application/json"],
259
      "responses": {
260
        "200": {
261
          "description": "Updated profile",
262
          "schema": {
263
            "$ref": "../definitions.json#/import-batch-profile"
264
          }
265
        },
266
        "400": {
267
          "description": "Missing or wrong parameters",
268
          "schema": {
269
            "$ref": "../definitions.json#/error"
270
          }
271
        },
272
        "401": {
273
          "description": "Authentication required",
274
          "schema": {
275
            "$ref": "../definitions.json#/error"
276
          }
277
        },
278
        "403": {
279
          "description": "Hold not allowed",
280
          "schema": {
281
            "$ref": "../definitions.json#/error"
282
          }
283
        },
284
        "404": {
285
          "description": "Borrower not found",
286
          "schema": {
287
            "$ref": "../definitions.json#/error"
288
          }
289
        },
290
        "500": {
291
          "description": "Internal server error",
292
          "schema": {
293
            "$ref": "../definitions.json#/error"
294
          }
295
        },
296
        "503": {
297
          "description": "Under maintenance",
298
          "schema": {
299
            "$ref": "../definitions.json#/error"
300
          }
301
        }
302
      },
303
      "x-koha-authorization": {
304
        "permissions": {
305
          "catalogue": "1"
306
        }
307
      }
308
    },
309
    "delete": {
310
      "x-mojo-to": "ImportBatchProfiles#delete",
311
      "operationId": "deleteImportBatchProfiles",
312
      "tags": ["ImportBatchProfiles"],
313
      "parameters": [{
314
          "$ref": "../parameters.json#/profile_id_pp"
315
        }
316
      ],
317
      "produces": ["application/json"],
318
      "responses": {
319
        "204": {
320
          "description": "Profile deleted"
321
        },
322
        "401": {
323
          "description": "Authentication required",
324
          "schema": {
325
            "$ref": "../definitions.json#/error"
326
          }
327
        },
328
        "403": {
329
          "description": "Hold not allowed",
330
          "schema": {
331
            "$ref": "../definitions.json#/error"
332
          }
333
        },
334
        "404": {
335
          "description": "Hold not found",
336
          "schema": {
337
            "$ref": "../definitions.json#/error"
338
          }
339
        },
340
        "500": {
341
          "description": "Internal server error",
342
          "schema": {
343
            "$ref": "../definitions.json#/error"
344
          }
345
        },
346
        "503": {
347
          "description": "Under maintenance",
348
          "schema": {
349
            "$ref": "../definitions.json#/error"
350
          }
351
        }
352
      },
353
      "x-koha-authorization": {
354
        "permissions": {
355
          "catalogue": "1"
356
        }
357
      }
358
    }
359
  }
360
}
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/manage-marc-import.tt (+3 lines)
Lines 106-111 Link Here
106
                        <fieldset class="rows" id="staged-record-matching-rules">
106
                        <fieldset class="rows" id="staged-record-matching-rules">
107
                            <ol>
107
                            <ol>
108
                                <li><span class="label">File name:</span> [% file_name | html %]</li>
108
                                <li><span class="label">File name:</span> [% file_name | html %]</li>
109
                                <li><span class="label">Profile:</span> [% IF (profile) %][% profile | html %][% ELSE %](none)[% END %]</li>
109
                                <li><span class="label">Comments:</span> [% IF ( comments ) %][% comments | html %][% ELSE %](none)[% END %]</li>
110
                                <li><span class="label">Comments:</span> [% IF ( comments ) %][% comments | html %][% ELSE %](none)[% END %]</li>
110
                                <li><span class="label">Type:</span> [% IF ( record_type == 'auth' ) %]Authority records[% ELSE %]Bibliographic records[% END %]</li>
111
                                <li><span class="label">Type:</span> [% IF ( record_type == 'auth' ) %]Authority records[% ELSE %]Bibliographic records[% END %]</li>
111
                                <li><span class="label">Staged:</span> [% upload_timestamp | $KohaDates with_hours=1 %]</li>
112
                                <li><span class="label">Staged:</span> [% upload_timestamp | $KohaDates with_hours=1 %]</li>
Lines 327-332 Link Here
327
                            <tr>
328
                            <tr>
328
                                <th>#</th>
329
                                <th>#</th>
329
                                <th>File name</th>
330
                                <th>File name</th>
331
                                <th>Profile</th>
330
                                <th>Comments</th>
332
                                <th>Comments</th>
331
                                <th>Type</th>
333
                                <th>Type</th>
332
                                <th>Status</th>
334
                                <th>Status</th>
Lines 339-344 Link Here
339
                                <tr>
341
                                <tr>
340
                                    <td>[% batch_lis.import_batch_id | html %]</td>
342
                                    <td>[% batch_lis.import_batch_id | html %]</td>
341
                                    <td><a href="[% batch_lis.script_name | url %]?import_batch_id=[% batch_lis.import_batch_id | uri %]">[% batch_lis.file_name | html %]</a></td>
343
                                    <td><a href="[% batch_lis.script_name | url %]?import_batch_id=[% batch_lis.import_batch_id | uri %]">[% batch_lis.file_name | html %]</a></td>
344
                                    <td>[% batch_lis.profile | html %]</td>
342
                                    <td>[% batch_lis.comments | html %]</td>
345
                                    <td>[% batch_lis.comments | html %]</td>
343
                                    <td>[% IF ( batch_lis.record_type == 'auth' ) %]Authority[% ELSE %]Bibliographic[% END %]</td>
346
                                    <td>[% IF ( batch_lis.record_type == 'auth' ) %]Authority[% ELSE %]Bibliographic[% END %]</td>
344
                                    <td>
347
                                    <td>
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/stage-marc-import.tt (+241 lines)
Lines 95-105 Link Here
95
    </div>
95
    </div>
96
</form>
96
</form>
97
97
98
<fieldset class="rows" id="profile_fieldset">
99
    <legend>Profile settings</legend>
100
    <ol>
101
        <li>
102
            <label for="profile">Pre fill values with profile</label>
103
            <select name="profile" id="profile">
104
                <option value="">Do not use profile</option>
105
            </select>
106
        </li>
107
        <li>
108
            <label for="profile_name">Profile name</label>
109
            <input type="text" id="profile_name" name="profile_name" />
110
111
        </li>
112
    </ol>
113
    <fieldset class="action">
114
        <button id="add_profile" disabled>Add profile</button>
115
        <button id="mod_profile" disabled>Update profile</button>
116
        <button id="del_profile" disabled>Remove profile</button>
117
    </fieldset>
118
</fieldset>
119
98
    <form method="post" id="processfile" action="[% SCRIPT_NAME | html %]" enctype="multipart/form-data">
120
    <form method="post" id="processfile" action="[% SCRIPT_NAME | html %]" enctype="multipart/form-data">
99
[% IF basketno && booksellerid %]
121
[% IF basketno && booksellerid %]
100
    <input type="hidden" name="basketno" id="basketno" value="[% basketno | html %]" />
122
    <input type="hidden" name="basketno" id="basketno" value="[% basketno | html %]" />
101
    <input type="hidden" name="booksellerid" id="booksellerid" value="[% booksellerid | html %]" />
123
    <input type="hidden" name="booksellerid" id="booksellerid" value="[% booksellerid | html %]" />
102
[% END %]
124
[% END %]
125
    <input type="hidden" name="profile_id" id="profile_id"/>
103
<fieldset class="rows">
126
<fieldset class="rows">
104
        <input type="hidden" name="uploadedfileid" id="uploadedfileid" value="" />
127
        <input type="hidden" name="uploadedfileid" id="uploadedfileid" value="" />
105
        <input type="hidden" name="runinbackground" id="runinbackground" value="" />
128
        <input type="hidden" name="runinbackground" id="runinbackground" value="" />
Lines 220-225 Link Here
220
        var xhr;
243
        var xhr;
221
        $(document).ready(function(){
244
        $(document).ready(function(){
222
            $("#processfile").hide();
245
            $("#processfile").hide();
246
            $('#profile_fieldset').hide();
223
            $("#record_type").change(function() {
247
            $("#record_type").change(function() {
224
                if ($(this).val() == 'auth') {
248
                if ($(this).val() == 'auth') {
225
                    $('#items').hide();
249
                    $('#items').hide();
Lines 238-243 Link Here
238
            $("#mainformsubmit").on("click",function(){
262
            $("#mainformsubmit").on("click",function(){
239
                return CheckForm( document.getElementById("processfile"));
263
                return CheckForm( document.getElementById("processfile"));
240
            });
264
            });
265
            getProfiles();
266
            $('#profile').change(function(){
267
                if(this.value=='') {
268
                    $("#mod_profile, #del_profile").prop("disabled",true);
269
                    $("#profile_id").val("");
270
                    $("#comments").val("");
271
                    $("#record_type").val('biblio').change();
272
                    $("#encoding").val('UTF-8').change();
273
                    $("#format").val('ISO2709').change();
274
                    $("#marc_modification_template_id").val("").change();
275
                    $("#matcher").val("").change();
276
                    $("#overlay_action").val('replace').change();
277
                    $("#nomatch_action").val('create_new').change();
278
                    $("#parse_itemsyes").prop("checked", true).change();
279
                    $("#item_action").val('always_add').change();
280
                    $("#profile_name").val('').keyup();
281
                } else {
282
                    const profile = $('option:selected', this).data('profile');
283
                    $("#profile_id").val(profile.profile_id);
284
                    $("#mod_profile, #del_profile").prop("disabled", null);
285
                    $("#comments").val(profile.comments);
286
                    $("#record_type").val(profile.record_type).change();
287
                    $("#encoding").val(profile.encoding).change();
288
                    $("#format").val(profile.format).change();
289
                    $("#marc_modification_template_id").val(profile.template_id).change();
290
                    $("#matcher").val(profile.matcher_id).change();
291
                    $("#overlay_action").val(profile.overlay_action).change();
292
                    $("#nomatch_action").val(profile.nomatch_action).change();
293
                    $("input[name='parse_items'][value='"+(profile.parse_items?'1':'0')+"']").prop("checked", true).change();
294
                    $("#item_action").val(profile.item_action).change();
295
                    $("#profile_name").val(profile.name).keyup();
296
                }
297
            });
298
299
            $("#profile_name").keyup(function(){
300
                $("#add_profile").prop("disabled", this.value.trim()=='');
301
                $("#mod_profile").prop("disabled", this.value.trim()=='' || !$("#profile").val())
302
            });
303
304
            $("#add_profile").click(function() {
305
                var name = $("#profile_name").val().trim();
306
                if(!name) {
307
                    alert(_("Profile must have a name"));
308
                    return;
309
                }
310
311
                var profile = $("#profile option[value!='']")
312
                    .map(function() {
313
                        return $(this).data('profile');
314
                    })
315
                    .filter(function() {
316
                        return this.name == name;
317
                    });
318
319
                if(profile.length) {
320
                    if(!confirm(_("There is another profile with this name.")+"\n\n"+_("Do you want to replace it?"))) {
321
                        return;
322
                    }
323
                }
324
325
                new Promise(function(resolve, reject) {
326
327
                    const params = {
328
                        comments: $("#comments").val() || null,
329
                        record_type: $("#record_type").val() || null,
330
                        encoding: $("#encoding").val() || null,
331
                        format: $("#format").val() || null,
332
                        template_id: $("#marc_modification_template_id").val() || null,
333
                        matcher_id: $("#matcher").val() || null,
334
                        overlay_action: $("#overlay_action").val() || null,
335
                        nomatch_action: $("#nomatch_action").val() || null,
336
                        parse_items: !!parseInt($("input[name='parse_items']:checked").val()) || null,
337
                        item_action: $("#item_action").val() || null,
338
                        name: name
339
                    };
340
341
                    if(profile.length) {
342
                        $.ajax({
343
                            url: "/api/v1/import-batch-profiles/"+profile[0].profile_id,
344
                            method: "PUT",
345
                            data: JSON.stringify(params),
346
                            contentType: 'application/json'
347
                        })
348
                        .done(resolve)
349
                        .fail(reject);
350
                    } else {
351
                        $.ajax({
352
                            url: "/api/v1/import-batch-profiles/",
353
                            method: "POST",
354
                            data: JSON.stringify(params),
355
                            contentType: 'application/json'
356
                        })
357
                        .done(resolve)
358
                        .fail(reject);
359
                    }
360
                })
361
                .then(function(profile) {
362
                    return getProfiles(profile.profile_id);
363
                })
364
                .catch(function(error) {
365
                    alert(_("An error occurred")+"\n\n"+error);
366
                })
367
            });
368
369
            $("#mod_profile").click(function() {
370
                var name = $("#profile_name").val().trim();
371
                var id = $("#profile").val();
372
                if(!id) return;
373
                if(!name) {
374
                    alert(_("Profile must have a name"));
375
                    return;
376
                }
377
                var profile = $("#profile option[value!='']")
378
                    .map(function() {
379
                        return $(this).data('profile');
380
                    })
381
                    .filter(function() {
382
                        return this.name == name && this.profile_id != id;
383
                    });
384
385
                if(profile.length) {
386
                    if(!confirm(_("There is another profile with this name.")+"\n\n"+_("Do you want to replace it?"))) {
387
                        return;
388
                    }
389
                }
390
                new Promise(function(resolve, reject) {
391
                    if(!profile.length) return resolve();
392
                    $.ajax({
393
                        url: "/api/v1/import-batch-profiles/"+profile[0].profile_id,
394
                        method: "DELETE"
395
                    })
396
                    .done(resolve)
397
                    .fail(reject);
398
                })
399
                .then(function(){
400
                    const params = {
401
                        comments: $("#comments").val() || null,
402
                        record_type: $("#record_type").val() || null,
403
                        encoding: $("#encoding").val() || null,
404
                        format: $("#format").val() || null,
405
                        template_id: $("#marc_modification_template_id").val() || null,
406
                        matcher_id: $("#matcher").val() || null,
407
                        overlay_action: $("#overlay_action").val() || null,
408
                        nomatch_action: $("#nomatch_action").val() || null,
409
                        parse_items: !!parseInt($("input[name='parse_items']:checked").val()) || null,
410
                        item_action: $("#item_action").val() || null,
411
                        name: name
412
                    };
413
                    return new Promise(function(resolve, reject) {
414
                        $.ajax({
415
                            url: "/api/v1/import-batch-profiles/"+id,
416
                            method: "PUT",
417
                            data: JSON.stringify(params),
418
                            contentType: 'application/json'
419
                        })
420
                        .done(resolve)
421
                        .fail(reject);
422
                    });
423
                })
424
                .then(function() {
425
                    return getProfiles(id);
426
                })
427
                .catch(function(error) {
428
                    alert(_("An error occurred")+"\n\n"+error.message);
429
                })
430
            });
431
432
            $("#del_profile").click(function() {
433
                var id = $("#profile").val();
434
                if(!id) return;
435
                if(!confirm(_("Are you sure you want to delete this profile?"))) {
436
                    return;
437
                }
438
                new Promise(function(resolve, reject) {
439
                    $.ajax({
440
                        url: "/api/v1/import-batch-profiles/"+id,
441
                        method: "DELETE"
442
                    })
443
                    .done(resolve)
444
                    .fail(reject);
445
                })
446
                .then(function() {
447
                    return getProfiles();
448
                })
449
                .catch(function(error) {
450
                    alert(_("An error occurred")+"\n\n"+error);
451
                })
452
            });
453
241
        });
454
        });
242
        function CheckForm(f) {
455
        function CheckForm(f) {
243
            if ($("#fileToUpload").value == '') {
456
            if ($("#fileToUpload").value == '') {
Lines 252-257 Link Here
252
            $('#fileuploadbutton').hide();
465
            $('#fileuploadbutton').hide();
253
            $("#fileuploadfailed").hide();
466
            $("#fileuploadfailed").hide();
254
            $("#processfile").hide();
467
            $("#processfile").hide();
468
            $('#profile_fieldset').hide();
255
            $("#fileuploadstatus").show();
469
            $("#fileuploadstatus").show();
256
            $("#uploadedfileid").val('');
470
            $("#uploadedfileid").val('');
257
            xhr= AjaxUpload( $('#fileToUpload'), $('#fileuploadprogress'), 'temp=1', cbUpload );
471
            xhr= AjaxUpload( $('#fileToUpload'), $('#fileuploadprogress'), 'temp=1', cbUpload );
Lines 277-282 Link Here
277
                    $('#format').val('MARCXML');
491
                    $('#format').val('MARCXML');
278
                }
492
                }
279
                $("#processfile").show();
493
                $("#processfile").show();
494
                $('#profile_fieldset').show();
280
            } else {
495
            } else {
281
                var errMsgs = [ _("Error code 0 not used"), _("File already exists"), _("Directory is not writeable"), _("Root directory for uploads not defined"), _("Temporary directory for uploads not defined") ];
496
                var errMsgs = [ _("Error code 0 not used"), _("File already exists"), _("Directory is not writeable"), _("Root directory for uploads not defined"), _("Temporary directory for uploads not defined") ];
282
                var errCode = errors[$('#fileToUpload').prop('files')[0].name].code;
497
                var errCode = errors[$('#fileToUpload').prop('files')[0].name].code;
Lines 290-295 Link Here
290
                );
505
                );
291
            }
506
            }
292
        }
507
        }
508
509
        function getProfiles(id) {
510
            const select = $("#profile");
511
            $("option[value!='']", select).remove();
512
            return new Promise(function(resolve, reject) {
513
                $.ajax("/api/v1/import-batch-profiles")
514
                .then(resolve, reject);
515
            })
516
            .then(function(profiles) {
517
                profiles.forEach(function(profile) {
518
                    const opt = $("<option/>");
519
                    select.append(opt);
520
                    if(id && profile.profile_id == id) {
521
                        opt.prop('selected', true);
522
                    }
523
                    opt.attr("value", profile.profile_id);
524
                    opt.html(profile.name);
525
                    opt.data("profile", profile);
526
                });
527
            })
528
            .then(function(){
529
                select.change();
530
            });
531
        }
532
533
293
    </script>
534
    </script>
294
[% END %]
535
[% END %]
295
536
(-)a/tools/manage-marc-import.pl (+2 lines)
Lines 216-221 sub import_batches_list { Link Here
216
            comments => $batch->{'comments'},
216
            comments => $batch->{'comments'},
217
            can_clean => ($batch->{'import_status'} ne 'cleaned') ? 1 : 0,
217
            can_clean => ($batch->{'import_status'} ne 'cleaned') ? 1 : 0,
218
            record_type => $batch->{'record_type'},
218
            record_type => $batch->{'record_type'},
219
            profile => $batch->{'profile'},
219
        };
220
        };
220
    }
221
    }
221
    $template->param(batch_list => \@list); 
222
    $template->param(batch_list => \@list); 
Lines 390-395 sub batch_info { Link Here
390
    my ($template, $batch) = @_;
391
    my ($template, $batch) = @_;
391
    $template->param(batch_info => 1);
392
    $template->param(batch_info => 1);
392
    $template->param(file_name => $batch->{'file_name'});
393
    $template->param(file_name => $batch->{'file_name'});
394
    $template->param(profile => $batch->{'profile'});
393
    $template->param(comments => $batch->{'comments'});
395
    $template->param(comments => $batch->{'comments'});
394
    $template->param(import_status => $batch->{'import_status'});
396
    $template->param(import_status => $batch->{'import_status'});
395
    $template->param(upload_timestamp => $batch->{'upload_timestamp'});
397
    $template->param(upload_timestamp => $batch->{'upload_timestamp'});
(-)a/tools/stage-marc-import.pl (-1 / +7 lines)
Lines 42-47 use Koha::UploadedFiles; Link Here
42
use C4::BackgroundJob;
42
use C4::BackgroundJob;
43
use C4::MarcModificationTemplates;
43
use C4::MarcModificationTemplates;
44
use Koha::Plugins;
44
use Koha::Plugins;
45
use Koha::ImportBatches;
45
46
46
my $input = CGI->new;
47
my $input = CGI->new;
47
48
Lines 60-65 my $format = $input->param('format') || 'ISO2709'; Link Here
60
my $marc_modification_template = $input->param('marc_modification_template_id');
61
my $marc_modification_template = $input->param('marc_modification_template_id');
61
my $basketno                   = $input->param('basketno');
62
my $basketno                   = $input->param('basketno');
62
my $booksellerid               = $input->param('booksellerid');
63
my $booksellerid               = $input->param('booksellerid');
64
my $profile_id                 = $input->param('profile_id');
63
65
64
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
66
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
65
    {
67
    {
Lines 151-156 if ($completedJobID) { Link Here
151
        50, staging_progress_callback( $job, $dbh )
153
        50, staging_progress_callback( $job, $dbh )
152
      );
154
      );
153
155
156
    if($profile_id) {
157
        my $ibatch = Koha::ImportBatches->find($batch_id);
158
        $ibatch->set({profile_id => $profile_id})->store;
159
    }
160
154
    my $num_with_matches = 0;
161
    my $num_with_matches = 0;
155
    my $checked_matches = 0;
162
    my $checked_matches = 0;
156
    my $matcher_failed = 0;
163
    my $matcher_failed = 0;
157
- 

Return to bug 23019