質問編集履歴
2
ソースコード追加と追加記入
test
CHANGED
File without changes
|
test
CHANGED
@@ -259,3 +259,217 @@
|
|
259
259
|
});
|
260
260
|
|
261
261
|
```
|
262
|
+
|
263
|
+
|
264
|
+
|
265
|
+
* サーバサイドのソースコードも省略して添付します。長いので簡単に説明すると、CSVファイル読んでDBに同じ値があれば更新、なければ採番テーブルからIDXをとってきて新規登録です。また、付加的な情報があるのでサブテーブルにも値を入れるために既存のデータを削除して再登録という感じです。(ですので、かなりDB作業が多いです。)
|
266
|
+
|
267
|
+
```PHP
|
268
|
+
|
269
|
+
public function import()
|
270
|
+
|
271
|
+
{
|
272
|
+
|
273
|
+
if($this->request->is('ajax'))
|
274
|
+
|
275
|
+
{
|
276
|
+
|
277
|
+
// Data set
|
278
|
+
|
279
|
+
$csv_subject_idx = $csvContent[0];
|
280
|
+
|
281
|
+
$csv_subject_year = $csvContent[1];
|
282
|
+
|
283
|
+
// 省略、作成日や作成者等色んな値を設定します。
|
284
|
+
|
285
|
+
|
286
|
+
|
287
|
+
if($customer_idx == $csv_customer_idx && $year == $csv_subject_year)
|
288
|
+
|
289
|
+
{
|
290
|
+
|
291
|
+
$subject = $this->Subject->find()->where(['customer_idx' => $csv_customer_idx])
|
292
|
+
|
293
|
+
->andWhere(['subject_idx' => $csv_subject_idx])
|
294
|
+
|
295
|
+
|
296
|
+
|
297
|
+
->select(['subject_idx',
|
298
|
+
|
299
|
+
'year',
|
300
|
+
|
301
|
+
'customer_idx',
|
302
|
+
|
303
|
+
'subject_name',
|
304
|
+
|
305
|
+
'subject_short',
|
306
|
+
|
307
|
+
])
|
308
|
+
|
309
|
+
->epilog('FOR UPDATE')
|
310
|
+
|
311
|
+
->toArray();
|
312
|
+
|
313
|
+
if(empty($subject))
|
314
|
+
|
315
|
+
{
|
316
|
+
|
317
|
+
// Insert
|
318
|
+
|
319
|
+
$master_type = 'SJ';
|
320
|
+
|
321
|
+
//採番テーブルのデータを持ってきて入れる
|
322
|
+
|
323
|
+
|
324
|
+
|
325
|
+
$query = $this->Masters->find()->where(['customer_idx' => $customer_idx, 'master_type' => $master_type])
|
326
|
+
|
327
|
+
->andWhere(['deleter IS NULL','deleted IS NULL'])
|
328
|
+
|
329
|
+
->epilog('FOR UPDATE');
|
330
|
+
|
331
|
+
$master = $query->first();
|
332
|
+
|
333
|
+
|
334
|
+
|
335
|
+
if(!empty($master))
|
336
|
+
|
337
|
+
{
|
338
|
+
|
339
|
+
// Master_indexテーブルにデータを追加し、Current_idxを1増加させる。
|
340
|
+
|
341
|
+
$current_idx = $master->current_idx + 1;
|
342
|
+
|
343
|
+
$query = $this->Masters->query();
|
344
|
+
|
345
|
+
$query->update()
|
346
|
+
|
347
|
+
->set(['current_idx' => $current_idx,
|
348
|
+
|
349
|
+
'modifier' => $modifier,
|
350
|
+
|
351
|
+
'modified' => $now])
|
352
|
+
|
353
|
+
->where(['customer_idx' => $customer_idx, 'master_type' => $master_type])
|
354
|
+
|
355
|
+
->execute();
|
356
|
+
|
357
|
+
}
|
358
|
+
|
359
|
+
|
360
|
+
|
361
|
+
//データセット
|
362
|
+
|
363
|
+
$subject_data = [
|
364
|
+
|
365
|
+
'subject_idx' => $current_idx,
|
366
|
+
|
367
|
+
'year' => $csv_subject_year,
|
368
|
+
|
369
|
+
'customer_idx' => $customer_idx,
|
370
|
+
|
371
|
+
'subject_name' => $csv_subject_name,
|
372
|
+
|
373
|
+
'subject_short' => $csv_subject_short,
|
374
|
+
|
375
|
+
|
376
|
+
|
377
|
+
];
|
378
|
+
|
379
|
+
|
380
|
+
|
381
|
+
$query = $this->Subject->query();
|
382
|
+
|
383
|
+
$query->insert([
|
384
|
+
|
385
|
+
'subject_idx',
|
386
|
+
|
387
|
+
'year',
|
388
|
+
|
389
|
+
'customer_idx',
|
390
|
+
|
391
|
+
'subject_name',
|
392
|
+
|
393
|
+
'subject_short',
|
394
|
+
|
395
|
+
|
396
|
+
|
397
|
+
]);
|
398
|
+
|
399
|
+
$query->values($subject_data);
|
400
|
+
|
401
|
+
$query->execute();
|
402
|
+
|
403
|
+
|
404
|
+
|
405
|
+
$count_insert = $count_insert + 1;
|
406
|
+
|
407
|
+
|
408
|
+
|
409
|
+
// subject_participant Table Delete with subject_idx // Table subject_participant Insert
|
410
|
+
|
411
|
+
// Table subject_equipment Insert
|
412
|
+
|
413
|
+
|
414
|
+
|
415
|
+
else
|
416
|
+
|
417
|
+
{
|
418
|
+
|
419
|
+
// Table subject Update
|
420
|
+
|
421
|
+
// subject_participant Table Delete with subject_idx
|
422
|
+
|
423
|
+
|
424
|
+
|
425
|
+
// subject_participant Table Insert
|
426
|
+
|
427
|
+
|
428
|
+
|
429
|
+
|
430
|
+
|
431
|
+
}
|
432
|
+
|
433
|
+
}
|
434
|
+
|
435
|
+
unset($participants);
|
436
|
+
|
437
|
+
}
|
438
|
+
|
439
|
+
|
440
|
+
|
441
|
+
// subject_equipment Table Delete with subject_idx
|
442
|
+
|
443
|
+
|
444
|
+
|
445
|
+
|
446
|
+
|
447
|
+
// subject_equipment Table Insert
|
448
|
+
|
449
|
+
|
450
|
+
|
451
|
+
}
|
452
|
+
|
453
|
+
}
|
454
|
+
|
455
|
+
unset($equipments);
|
456
|
+
|
457
|
+
}
|
458
|
+
|
459
|
+
}
|
460
|
+
|
461
|
+
// 他のソースは省略
|
462
|
+
|
463
|
+
}
|
464
|
+
|
465
|
+
}
|
466
|
+
|
467
|
+
}
|
468
|
+
|
469
|
+
```
|
470
|
+
|
471
|
+
|
472
|
+
|
473
|
+
*追加(2018年2月1日)
|
474
|
+
|
475
|
+
PHP.iniの設定でメモリーを128MBー>512MBに、POSTデータのサイズを40MBー>100MBに変更してみましたが結果は同じでした。
|
1
内容追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -42,7 +42,17 @@
|
|
42
42
|
|
43
43
|
|
44
44
|
|
45
|
-
chromeのデバッグツールでみたら、ファイルからデータは全て取れてます。たぶん、問題はそれをajaxのpostで送信する時に、サイズの制限又はメモリー容量の問題か、上のメッセージ
|
45
|
+
chromeのデバッグツールでみたら、ファイルからデータは全て取れてます。たぶん、問題はそれをajaxのpostで送信する時に、サイズの制限又はメモリー容量の問題か、ファイルの途中までしか飲みとれず、DBにInsertする時に配列に値がないという感じで上のメッセージが出されて動かないです。もちろん、50行未満のファイルをImportすると問題なく上手く動きます。
|
46
|
+
|
47
|
+
例えば、こんな感じですね。
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
"53","2017","7","共・高2組2","1","1","1","1","","true","",""
|
52
|
+
|
53
|
+
"54","2017","7","必・高, null, null, null, null, null, null, null, null
|
54
|
+
|
55
|
+
(元のデータは、"54","2017","7","必・高2組3, ","1","1","1","1","","true","","" です。)
|
46
56
|
|
47
57
|
|
48
58
|
|