Skip to content

Commit

Permalink
extended extension to 3 weeks
Browse files Browse the repository at this point in the history
  • Loading branch information
jzakotnik committed Sep 22, 2023
1 parent 3ce52f8 commit 61324d2
Show file tree
Hide file tree
Showing 8 changed files with 81 additions and 78 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ Edit-Screen

### Bare metal am Beispiel Raspberry Pi

- Beschreibung folgt

### Docker

- Baue das image mit `docker build --no-cache -t openlibry .`
Expand Down
134 changes: 69 additions & 65 deletions doc/OpenBiblioImport.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,76 +20,80 @@ podman machine start
- Create a database with name openbiblio in phpmyadmin running on `http://localhost:8080/`
- Copy the files over the running container
``
podman cp ./input-21-07-2023/biblio.MYD mysql-server-db:/var/lib/mysql/openbiblio
podman cp ./input-21-07-2023/biblio.MYI mysql-server-db:/var/lib/mysql/openbiblio
podman cp ./input-21-07-2023/biblio.frm mysql-server-db:/var/lib/mysql/openbiblio
podman cp ./input-21-07-2023/biblio_copy.MYD mysql-server-db:/var/lib/mysql/openbiblio
podman cp ./input-21-07-2023/biblio_copy.MYI mysql-server-db:/var/lib/mysql/openbiblio
podman cp ./input-21-07-2023/biblio_copy.frm mysql-server-db:/var/lib/mysql/openbiblio
podman cp ./input-21-07-2023/biblio_field.MYD mysql-server-db:/var/lib/mysql/openbiblio
podman cp ./input-21-07-2023/biblio_field.MYI mysql-server-db:/var/lib/mysql/openbiblio
podman cp ./input-21-07-2023/biblio_field.frm mysql-server-db:/var/lib/mysql/openbiblio
podman cp ./input-21-07-2023/biblio_hold.MYD mysql-server-db:/var/lib/mysql/openbiblio
podman cp ./input-21-07-2023/biblio_hold.MYI mysql-server-db:/var/lib/mysql/openbiblio
podman cp ./input-21-07-2023/biblio_hold.frm mysql-server-db:/var/lib/mysql/openbiblio
podman cp ./input-21-07-2023/biblio_status_dm.MYD mysql-server-db:/var/lib/mysql/openbiblio
podman cp ./input-21-07-2023/biblio_status_dm.MYI mysql-server-db:/var/lib/mysql/openbiblio
podman cp ./input-21-07-2023/biblio_status_dm.frm mysql-server-db:/var/lib/mysql/openbiblio
podman cp ./input-21-07-2023/biblio_status_hist.MYD mysql-server-db:/var/lib/mysql/openbiblio
podman cp ./input-21-07-2023/biblio_status_hist.MYI mysql-server-db:/var/lib/mysql/openbiblio
podman cp ./input-21-07-2023/biblio_status_hist.frm mysql-server-db:/var/lib/mysql/openbiblio
podman cp ./input-21-07-2023/collection_dm.MYD mysql-server-db:/var/lib/mysql/openbiblio
podman cp ./input-21-07-2023/collection_dm.MYI mysql-server-db:/var/lib/mysql/openbiblio
podman cp ./input-21-07-2023/collection_dm.frm mysql-server-db:/var/lib/mysql/openbiblio
podman cp ./input-21-07-2023/db.opt mysql-server-db:/var/lib/mysql/openbiblio
podman cp ./input-21-07-2023/material_type_dm.MYD mysql-server-db:/var/lib/mysql/openbiblio
podman cp ./input-21-07-2023/material_type_dm.MYI mysql-server-db:/var/lib/mysql/openbiblio
podman cp ./input-21-07-2023/material_type_dm.frm mysql-server-db:/var/lib/mysql/openbiblio
podman cp ./input-21-07-2023/mbr_classify_dm.MYD mysql-server-db:/var/lib/mysql/openbiblio
podman cp ./input-21-07-2023/mbr_classify_dm.MYI mysql-server-db:/var/lib/mysql/openbiblio
podman cp ./input-21-07-2023/mbr_classify_dm.frm mysql-server-db:/var/lib/mysql/openbiblio
podman cp ./input-21-07-2023/member.MYD mysql-server-db:/var/lib/mysql/openbiblio
podman cp ./input-21-07-2023/member.MYI mysql-server-db:/var/lib/mysql/openbiblio
podman cp ./input-21-07-2023/member.frm mysql-server-db:/var/lib/mysql/openbiblio
podman cp ./input-21-07-2023/member_account.MYD mysql-server-db:/var/lib/mysql/openbiblio
podman cp ./input-21-07-2023/member_account.MYI mysql-server-db:/var/lib/mysql/openbiblio
podman cp ./input-21-07-2023/member_account.frm mysql-server-db:/var/lib/mysql/openbiblio
podman cp ./input-21-07-2023/session.MYD mysql-server-db:/var/lib/mysql/openbiblio
podman cp ./input-21-07-2023/session.MYI mysql-server-db:/var/lib/mysql/openbiblio
podman cp ./input-21-07-2023/session.frm mysql-server-db:/var/lib/mysql/openbiblio
podman cp ./input-21-07-2023/settings.MYD mysql-server-db:/var/lib/mysql/openbiblio
podman cp ./input-21-07-2023/settings.MYI mysql-server-db:/var/lib/mysql/openbiblio
podman cp ./input-21-07-2023/settings.frm mysql-server-db:/var/lib/mysql/openbiblio
podman cp ./input-21-07-2023/staff.MYD mysql-server-db:/var/lib/mysql/openbiblio
podman cp ./input-21-07-2023/staff.MYI mysql-server-db:/var/lib/mysql/openbiblio
podman cp ./input-21-07-2023/staff.frm mysql-server-db:/var/lib/mysql/openbiblio
podman cp ./input-21-07-2023/state_dm.MYD mysql-server-db:/var/lib/mysql/openbiblio
podman cp ./input-21-07-2023/state_dm.MYI mysql-server-db:/var/lib/mysql/openbiblio
podman cp ./input-21-07-2023/state_dm.frm mysql-server-db:/var/lib/mysql/openbiblio
podman cp ./input-21-07-2023/theme.MYD mysql-server-db:/var/lib/mysql/openbiblio
podman cp ./input-21-07-2023/theme.MYI mysql-server-db:/var/lib/mysql/openbiblio
podman cp ./input-21-07-2023/theme.frm mysql-server-db:/var/lib/mysql/openbiblio
podman cp ./input-21-07-2023/transaction_type_dm.MYD mysql-server-db:/var/lib/mysql/openbiblio
podman cp ./input-21-07-2023/transaction_type_dm.MYI mysql-server-db:/var/lib/mysql/openbiblio
podman cp ./input-21-07-2023/transaction_type_dm.frm mysql-server-db:/var/lib/mysql/openbiblio
podman cp ./input-21-07-2023/usmarc_block_dm.MYD mysql-server-db:/var/lib/mysql/openbiblio
podman cp ./input-21-07-2023/usmarc_block_dm.MYI mysql-server-db:/var/lib/mysql/openbiblio
podman cp ./input-21-07-2023/usmarc_block_dm.frm mysql-server-db:/var/lib/mysql/openbiblio
podman cp ./input-21-07-2023/usmarc_indicator_dm.MYD mysql-server-db:/var/lib/mysql/openbiblio
podman cp ./input-21-07-2023/usmarc_indicator_dm.MYI mysql-server-db:/var/lib/mysql/openbiblio
podman cp ./input-21-07-2023/usmarc_indicator_dm.frm mysql-server-db:/var/lib/mysql/openbiblio
podman cp ./input-21-07-2023/usmarc_subfield_dm.MYD mysql-server-db:/var/lib/mysql/openbiblio
podman cp ./input-21-07-2023/usmarc_subfield_dm.MYI mysql-server-db:/var/lib/mysql/openbiblio
podman cp ./input-21-07-2023/usmarc_subfield_dm.frm mysql-server-db:/var/lib/mysql/openbiblio
podman cp ./input-21-07-2023/usmarc_tag_dm.MYD mysql-server-db:/var/lib/mysql/openbiblio
podman cp ./input-21-07-2023/usmarc_tag_dm.MYI mysql-server-db:/var/lib/mysql/openbiblio
podman cp ./input-21-07-2023/usmarc_tag_dm.frm mysql-server-db:/var/lib/mysql/openbiblio
podman cp ./input-22-09-2023/biblio.MYD mysql-server-db:/var/lib/mysql/openbiblio
podman cp ./input-22-09-2023/biblio.MYI mysql-server-db:/var/lib/mysql/openbiblio
podman cp ./input-22-09-2023/biblio.frm mysql-server-db:/var/lib/mysql/openbiblio
podman cp ./input-22-09-2023/biblio_copy.MYD mysql-server-db:/var/lib/mysql/openbiblio
podman cp ./input-22-09-2023/biblio_copy.MYI mysql-server-db:/var/lib/mysql/openbiblio
podman cp ./input-22-09-2023/biblio_copy.frm mysql-server-db:/var/lib/mysql/openbiblio
podman cp ./input-22-09-2023/biblio_field.MYD mysql-server-db:/var/lib/mysql/openbiblio
podman cp ./input-22-09-2023/biblio_field.MYI mysql-server-db:/var/lib/mysql/openbiblio
podman cp ./input-22-09-2023/biblio_field.frm mysql-server-db:/var/lib/mysql/openbiblio
podman cp ./input-22-09-2023/biblio_hold.MYD mysql-server-db:/var/lib/mysql/openbiblio
podman cp ./input-22-09-2023/biblio_hold.MYI mysql-server-db:/var/lib/mysql/openbiblio
podman cp ./input-22-09-2023/biblio_hold.frm mysql-server-db:/var/lib/mysql/openbiblio
podman cp ./input-22-09-2023/biblio_status_dm.MYD mysql-server-db:/var/lib/mysql/openbiblio
podman cp ./input-22-09-2023/biblio_status_dm.MYI mysql-server-db:/var/lib/mysql/openbiblio
podman cp ./input-22-09-2023/biblio_status_dm.frm mysql-server-db:/var/lib/mysql/openbiblio
podman cp ./input-22-09-2023/biblio_status_hist.MYD mysql-server-db:/var/lib/mysql/openbiblio
podman cp ./input-22-09-2023/biblio_status_hist.MYI mysql-server-db:/var/lib/mysql/openbiblio
podman cp ./input-22-09-2023/biblio_status_hist.frm mysql-server-db:/var/lib/mysql/openbiblio
podman cp ./input-22-09-2023/collection_dm.MYD mysql-server-db:/var/lib/mysql/openbiblio
podman cp ./input-22-09-2023/collection_dm.MYI mysql-server-db:/var/lib/mysql/openbiblio
podman cp ./input-22-09-2023/collection_dm.frm mysql-server-db:/var/lib/mysql/openbiblio
podman cp ./input-22-09-2023/db.opt mysql-server-db:/var/lib/mysql/openbiblio
podman cp ./input-22-09-2023/material_type_dm.MYD mysql-server-db:/var/lib/mysql/openbiblio
podman cp ./input-22-09-2023/material_type_dm.MYI mysql-server-db:/var/lib/mysql/openbiblio
podman cp ./input-22-09-2023/material_type_dm.frm mysql-server-db:/var/lib/mysql/openbiblio
podman cp ./input-22-09-2023/mbr_classify_dm.MYD mysql-server-db:/var/lib/mysql/openbiblio
podman cp ./input-22-09-2023/mbr_classify_dm.MYI mysql-server-db:/var/lib/mysql/openbiblio
podman cp ./input-22-09-2023/mbr_classify_dm.frm mysql-server-db:/var/lib/mysql/openbiblio
podman cp ./input-22-09-2023/member.MYD mysql-server-db:/var/lib/mysql/openbiblio
podman cp ./input-22-09-2023/member.MYI mysql-server-db:/var/lib/mysql/openbiblio
podman cp ./input-22-09-2023/member.frm mysql-server-db:/var/lib/mysql/openbiblio
podman cp ./input-22-09-2023/member_account.MYD mysql-server-db:/var/lib/mysql/openbiblio
podman cp ./input-22-09-2023/member_account.MYI mysql-server-db:/var/lib/mysql/openbiblio
podman cp ./input-22-09-2023/member_account.frm mysql-server-db:/var/lib/mysql/openbiblio
podman cp ./input-22-09-2023/session.MYD mysql-server-db:/var/lib/mysql/openbiblio
podman cp ./input-22-09-2023/session.MYI mysql-server-db:/var/lib/mysql/openbiblio
podman cp ./input-22-09-2023/session.frm mysql-server-db:/var/lib/mysql/openbiblio
podman cp ./input-22-09-2023/settings.MYD mysql-server-db:/var/lib/mysql/openbiblio
podman cp ./input-22-09-2023/settings.MYI mysql-server-db:/var/lib/mysql/openbiblio
podman cp ./input-22-09-2023/settings.frm mysql-server-db:/var/lib/mysql/openbiblio
podman cp ./input-22-09-2023/staff.MYD mysql-server-db:/var/lib/mysql/openbiblio
podman cp ./input-22-09-2023/staff.MYI mysql-server-db:/var/lib/mysql/openbiblio
podman cp ./input-22-09-2023/staff.frm mysql-server-db:/var/lib/mysql/openbiblio
podman cp ./input-22-09-2023/state_dm.MYD mysql-server-db:/var/lib/mysql/openbiblio
podman cp ./input-22-09-2023/state_dm.MYI mysql-server-db:/var/lib/mysql/openbiblio
podman cp ./input-22-09-2023/state_dm.frm mysql-server-db:/var/lib/mysql/openbiblio
podman cp ./input-22-09-2023/theme.MYD mysql-server-db:/var/lib/mysql/openbiblio
podman cp ./input-22-09-2023/theme.MYI mysql-server-db:/var/lib/mysql/openbiblio
podman cp ./input-22-09-2023/theme.frm mysql-server-db:/var/lib/mysql/openbiblio
podman cp ./input-22-09-2023/transaction_type_dm.MYD mysql-server-db:/var/lib/mysql/openbiblio
podman cp ./input-22-09-2023/transaction_type_dm.MYI mysql-server-db:/var/lib/mysql/openbiblio
podman cp ./input-22-09-2023/transaction_type_dm.frm mysql-server-db:/var/lib/mysql/openbiblio
podman cp ./input-22-09-2023/usmarc_block_dm.MYD mysql-server-db:/var/lib/mysql/openbiblio
podman cp ./input-22-09-2023/usmarc_block_dm.MYI mysql-server-db:/var/lib/mysql/openbiblio
podman cp ./input-22-09-2023/usmarc_block_dm.frm mysql-server-db:/var/lib/mysql/openbiblio
podman cp ./input-22-09-2023/usmarc_indicator_dm.MYD mysql-server-db:/var/lib/mysql/openbiblio
podman cp ./input-22-09-2023/usmarc_indicator_dm.MYI mysql-server-db:/var/lib/mysql/openbiblio
podman cp ./input-22-09-2023/usmarc_indicator_dm.frm mysql-server-db:/var/lib/mysql/openbiblio
podman cp ./input-22-09-2023/usmarc_subfield_dm.MYD mysql-server-db:/var/lib/mysql/openbiblio
podman cp ./input-22-09-2023/usmarc_subfield_dm.MYI mysql-server-db:/var/lib/mysql/openbiblio
podman cp ./input-22-09-2023/usmarc_subfield_dm.frm mysql-server-db:/var/lib/mysql/openbiblio
podman cp ./input-22-09-2023/usmarc_tag_dm.MYD mysql-server-db:/var/lib/mysql/openbiblio
podman cp ./input-22-09-2023/usmarc_tag_dm.MYI mysql-server-db:/var/lib/mysql/openbiblio
podman cp ./input-22-09-2023/usmarc_tag_dm.frm mysql-server-db:/var/lib/mysql/openbiblio
``

- Export the following tables as json, sort them by date `create_dt`: `member`, `biblio_status_hist`, `biblio`, `biblio_field`, `biblio_copy`. Copy them together in `book_all.json`. It is important to sort by date, because the history of rentals needs to be in the correct order. *IMPORTANT* don't click on export, first do the sorted SQL query and then export the query result as json.
- Export the following tables as json, sort them by date `create_dt`: `member`, `biblio_status_hist`, `biblio`, `biblio_field`, `biblio_copy`. Copy them together in `book_all.json` (this is a bit tedious). It is important to sort by date (oldest first), because the history of rentals needs to be in the correct order.
*IMPORTANT* don't click on export, first do the sorted SQL query and then export the query result as json. For example, the member export has the query `SELECT * FROM member ORDER BY member.create_dt ASC`
![book_all.json Structure](./openbiblio_import_structure.png)

- In openlibry delete the database file `dev.db` and the `migrations` folder if it exists. Then recreate them with `npx prisma migrate dev --name init`

- Run the app using `npm run dev`

- Use API to import members `curl -X POST -H "Content-Type: application/json" -d @member.json http://localhost:3000/api/openbiblioimport/migrateUsers`


Expand Down
Binary file added doc/openbiblio_import_structure.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion entities/book.ts
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ export async function rentBook(
client: PrismaClient,
userid: number,
bookid: number,
duration: number = 14
duration: number = 21
) {
//change due date, connect to user
//put all into one transaction
Expand Down
17 changes: 7 additions & 10 deletions pages/api/openbiblioimport/migrateBooks.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
import { PrismaClient } from "@prisma/client";
import { BookType } from "../../../entities/BookType";
import type { NextApiRequest, NextApiResponse } from "next";
import { addBook, deleteAllBooks } from "@/entities/book";
import { getUser } from "@/entities/user";
import { BookType } from "../../../entities/BookType";

import dayjs from "dayjs";
import timezone from "dayjs/plugin/timezone";
import customParseFormat from "dayjs/plugin/customParseFormat";
import timezone from "dayjs/plugin/timezone";
import utc from "dayjs/plugin/utc";
import { UserType } from "@/entities/UserType";

export const TIMEZONE = "Europe/Berlin";
dayjs.extend(utc);
Expand Down Expand Up @@ -237,7 +234,7 @@ export default async function handler(
const booklist = req.body as any;
//console.log("Booklist", booklist);
const bookCopy = booklist.biblio_copy[2].data;
//for some reason, the real ID of the book is in the hist table.. didn't get it
//for some reason, the real ID of the book is in the copy table.. didn't get it
const bookIDMapping = createBookIDMapping(bookCopy);
//filter out the books that have no barcode..
//console.log("Book ID Mapping", bookIDMapping);
Expand Down Expand Up @@ -294,7 +291,7 @@ export default async function handler(
(u.topic5 ??= " "),
imageLink: "",
} as BookType;
//console.log("Adding book", book);
console.log("Adding book", book);
//transaction.push(addBook(prisma, book));
//addBook(prisma, book);
transaction.push(prisma.book.create({ data: { ...book } }));
Expand All @@ -320,11 +317,11 @@ export default async function handler(
? dayjs(u.due_back_dt, "YYYY-MM-DD", true).toDate()
: undefined;

//console.log("Timestamps: ", rentedTime, dueDate);
console.log("Timestamps: ", rentedTime, dueDate);

//connect the book to the user, if it still exists

//console.log("Connecting user ", u.mbrid);
console.log("Connecting user ", u.mbrid);
if (existingUsers.has(parseInt(u.mbrid))) {
rentalStatusCount++;
transaction.push(
Expand Down Expand Up @@ -363,7 +360,7 @@ export default async function handler(

//Attach additional fields from the fields table in OpenBiblio
let additionalFieldsCount = 0;
//console.log(bookExtraFields);
console.log(bookExtraFields);
bookExtraFields.map((f: any) => {
const barcodeID = bookIDMapping[f.bibid];
if (isNaN(barcodeID)) {
Expand Down
2 changes: 1 addition & 1 deletion pages/rental/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export default function Rental({ books, users, rentals }: RentalPropsType) {
console.log("Extending book ", bookid, book);
const newbook = replaceBookStringDate(book) as any;
//extend logic
const newDueDate = extendWeeks(book.dueDate as Date, 2);
const newDueDate = extendWeeks(book.dueDate as Date, 3);
newbook.dueDate = newDueDate.toDate();
newbook.renewalCount = newbook.renewalCount + 1;

Expand Down
2 changes: 1 addition & 1 deletion pages/user/[userid].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ export default function UserDetail({ user, books }: any) {

const newbook = replaceBookStringDate(book) as any;
//extend logic
const newDueDate = extendWeeks(book.dueDate as Date, 2);
const newDueDate = extendWeeks(book.dueDate as Date, 3);
newbook.dueDate = newDueDate.toDate();
newbook.renewalCount = newbook.renewalCount + 1;

Expand Down

0 comments on commit 61324d2

Please sign in to comment.