nextcloud / calendar_resource_management

Resources back-end for the Nextcloud CalDAV server
https://apps.nextcloud.com/apps/calendar_resource_management
GNU Affero General Public License v3.0
61 stars 14 forks source link

Resources added via CLI are not found in Calendar #51

Closed miaulalala closed 2 months ago

miaulalala commented 2 years ago

The Job that is supposed to update the Calendar Rooms and Resources is not findng any backends in some cases but for others it works fine (like @ChristophWurst ).

Backends are collected in \OCP\Calendar\Room\IManager::getBackends

kpieth commented 2 years ago

I have the same problem. Resources are not shown in the calendar, but with calendar-resource:resources:list. Cron.php is running. Do you have anything i can test/debug? Version of app is "0.1.1-alpha.1" from git. Nextcloud 24.0.1.

rocramer commented 2 years ago

Same problem. I can see created resources on the CLI, but they can't be found via calendar.

smallfish01 commented 2 years ago

Same problem, who knows how to debug ?

miaulalala commented 2 years ago

Ok my issue is resolved with the most recent NC version (25 dev) and the most recent version of calendar_resources. I have no clue what the solution was, but I would suggest running composer on the NC root and the calendar resource management app.

unteem commented 2 years ago

Same issue here on NC version 23.0.10 which should still be supported. App version is 0.3.1 Can we re-open this issue, upgrading to nextcloud 25 dev does not feel like a proper fix. Thanks

bilyboy785 commented 1 year ago

Same problem here with :

Resource is OK in database :

MariaDB [nextcloud]> select * from calresources_vehicles;
+----+-------------+-----+--------------+-------+---------------+------------------------+--------------+--------------+---------------+-------------+-------+------------------+
| id | building_id | uid | display_name | email | resource_type | contact_person_user_id | vehicle_type | vehicle_make | vehicle_model | is_electric | range | seating_capacity |
+----+-------------+-----+--------------+-------+---------------+------------------------+--------------+--------------+---------------+-------------+-------+------------------+
|  3 |           1 | 1   | Renault Zoé  |       | vehicle       |                        | Citadine     | Renault      | Zoé           |           1 |   350 |                4 |
+----+-------------+-----+--------------+-------+---------------+------------------------+--------------+--------------+---------------+-------------+-------+------------------+
1 row in set (0.001 sec)
MariaDB [nextcloud]> select * from calresources_buildings;
+----+--------------+-------------+--------------+--------------------------+
| id | display_name | description | address      | is_wheelchair_accessible |
+----+--------------+-------------+--------------+--------------------------+
|  1 | Garage BSA   | Garage BSA  | La Ferrière  |                        0 |
+----+--------------+-------------+--------------+--------------------------+
1 row in set (0.000 sec)

And all seems to be OK in listing OCC :

Vehicles:
+----+-----+-------------+--------------+-------+----------------+----------+---------+-------+----------+-------+----------+
| ID | UID | Name        | Located in   | Email | Contact Person | Type     | Make    | Model | Electric | Range | Capacity |
+----+-----+-------------+--------------+-------+----------------+----------+---------+-------+----------+-------+----------+
| 3  | 1   | Renault Zoé | 1 Garage BSA |       |                | Citadine | Renault | Zoé   | yes      | 350   | 4        |
+----+-----+-------------+--------------+-------+----------------+----------+---------+-------+----------+-------+----------+
Buildings:
+----+------------+-------------+-------------+-----------------------+
| ID | Name       | Address     | Description | Wheelchair Accessible |
+----+------------+-------------+-------------+-----------------------+
| 1  | Garage BSA | La Ferrière | Garage BSA  | no                    |
+----+------------+-------------+-------------+-----------------------+

Do you have any information to how make it works ?

bilyboy785 commented 1 year ago

Any news on this issue ?

mark543g commented 1 year ago

waiting to sync data....and Maybe.....Need enter keywords in the search bar D_ROOM

bilyboy785 commented 1 year ago

@mark543g it doesn't work. Resources exists, but nothing found in the UI :

CleanShot 2022-11-24 at 08 11 48

CleanShot 2022-11-24 at 08 12 47

mark543g commented 1 year ago

check table "oc_calresources_rooms" when i use "select * from oc_calresources_rooms;" ,that can show each item

btw my nextcloud ver is 25.0.1 db_rooms

bilyboy785 commented 1 year ago

My table calresources_rooms is empty :

MariaDB [nextcloud]> select * from calresources_rooms; Empty set (0.001 sec)

miaulalala commented 1 year ago

My table calresources_rooms is empty :

MariaDB [nextcloud]> select * from calresources_rooms; Empty set (0.001 sec)

that is a good hint, thanks. I'm not sure but this could be an issue with how we formed the query.

Can you add an entry to your calresources_rooms table and see if that works?

mark543g commented 1 year ago

select * from calresources_vehicles;

The new version databas does not have this table (calresources_vehicles ) only "oc_calresources_vehicles" but...nextcloud database table does not have table "oc_calendar_vehicles" maybe ...The new version does not support vehicles

mark543g commented 1 year ago

m.............It works

occ_veh after 1.5 hour vehicle_01

bilyboy785 commented 1 year ago

Hey @mark543g how do you make it works ? Did u create the table oc_calendar_vehicles ?

mark543g commented 1 year ago

Hey @mark543g how do you make it works ? Did u create the table oc_calendar_vehicles ? also at talble "oc_calendar_resources" vehicle_on_resource

derBobby commented 1 year ago

I had the same problem and could fix it with the following steps. But I can't tell which steps are mandatory and which could have skipped.

Also this led me to the next issue: https://github.com/nextcloud/calendar_resource_management/issues/82

Steps

  1. Save the table definition ("SHOW CREATE TABLE ")
  2. Drop all tables
  3. Remove the plugin
  4. Restart Docker container
  5. Install the plugin
  6. Needed to create the tables MANUALLY, I don't know why
  7. Created my calendar resources
  8. Code

    To get the table definitions:

    SHOW CREATE TABLE calresources_buildings;
    SHOW CREATE TABLE calresources_stories;
    SHOW CREATE TABLE calresources_resources;
    SHOW CREATE TABLE calresources_rooms;
    SHOW CREATE TABLE calresources_restricts;
    SHOW CREATE TABLE calresources_vehicles;

    In my case, in order of execution, this were the table definitions:

    CREATE TABLE `calresources_buildings` (
      `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
      `display_name` varchar(255) COLLATE utf8mb4_bin NOT NULL,
      `description` varchar(4000) COLLATE utf8mb4_bin DEFAULT NULL,
      `address` varchar(4000) COLLATE utf8mb4_bin DEFAULT NULL,
      `is_wheelchair_accessible` tinyint(1) DEFAULT 0,
      PRIMARY KEY (`id`)
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;
    
    CREATE TABLE `calresources_stories` (
      `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
      `building_id` bigint(20) unsigned NOT NULL,
      `display_name` varchar(255) COLLATE utf8mb4_bin NOT NULL,
      PRIMARY KEY (`id`),
      KEY `calresources_stories_bid` (`building_id`),
      CONSTRAINT `FK_A7A2067F4D2A7E12` FOREIGN KEY (`building_id`) REFERENCES `calresources_buildings` (`id`) ON DELETE CASCADE
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;
    
    CREATE TABLE `calresources_resources` (
      `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
      `building_id` bigint(20) unsigned NOT NULL,
      `uid` varchar(255) COLLATE utf8mb4_bin NOT NULL,
      `display_name` varchar(255) COLLATE utf8mb4_bin NOT NULL,
      `email` varchar(255) COLLATE utf8mb4_bin NOT NULL,
      `resource_type` varchar(255) COLLATE utf8mb4_bin NOT NULL,
      `contact_person_user_id` varchar(255) COLLATE utf8mb4_bin DEFAULT NULL,
      PRIMARY KEY (`id`),
      UNIQUE KEY `calresources_resources_uid` (`uid`),
      UNIQUE KEY `calresources_resources_eml` (`email`),
      KEY `calresources_resources_bid` (`building_id`),
      CONSTRAINT `FK_1D3FBEE94D2A7E12` FOREIGN KEY (`building_id`) REFERENCES `calresources_buildings` (`id`) ON DELETE CASCADE
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;
    
    CREATE TABLE `calresources_rooms` (
      `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
      `story_id` bigint(20) unsigned NOT NULL,
      `uid` varchar(255) COLLATE utf8mb4_bin NOT NULL,
      `display_name` varchar(255) COLLATE utf8mb4_bin NOT NULL,
      `email` varchar(255) COLLATE utf8mb4_bin NOT NULL,
      `room_type` varchar(255) COLLATE utf8mb4_bin NOT NULL,
      `contact_person_user_id` varchar(255) COLLATE utf8mb4_bin DEFAULT NULL,
      `capacity` int(11) DEFAULT NULL,
      `room_number` varchar(255) COLLATE utf8mb4_bin DEFAULT NULL,
      `has_phone` tinyint(1) DEFAULT 0,
      `has_video_conferencing` tinyint(1) DEFAULT 0,
      `has_tv` tinyint(1) DEFAULT 0,
      `has_projector` tinyint(1) DEFAULT 0,
      `has_whiteboard` tinyint(1) DEFAULT 0,
      `is_wheelchair_accessible` tinyint(1) DEFAULT 0,
      PRIMARY KEY (`id`),
      UNIQUE KEY `calresources_rooms_uid` (`uid`),
      UNIQUE KEY `calresources_rooms_eml` (`email`),
      KEY `calresources_rooms_sid` (`story_id`),
      CONSTRAINT `FK_75864578AA5D4036` FOREIGN KEY (`story_id`) REFERENCES `calresources_stories` (`id`) ON DELETE CASCADE
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;
    
    CREATE TABLE `calresources_restricts` (
      `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
      `entity_type` varchar(255) COLLATE utf8mb4_bin NOT NULL,
      `entity_id` bigint(20) unsigned NOT NULL,
      `group_id` varchar(255) COLLATE utf8mb4_bin NOT NULL,
      PRIMARY KEY (`id`),
      UNIQUE KEY `calresources_restricts_eeg` (`entity_type`,`entity_id`,`group_id`),
      KEY `calresources_restricts_ent` (`entity_type`,`entity_id`)
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;
    
    CREATE TABLE `calresources_vehicles` (
      `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
      `building_id` bigint(20) unsigned NOT NULL,
      `uid` varchar(255) COLLATE utf8mb4_bin NOT NULL,
      `display_name` varchar(255) COLLATE utf8mb4_bin NOT NULL,
      `email` varchar(255) COLLATE utf8mb4_bin NOT NULL,
      `resource_type` varchar(255) COLLATE utf8mb4_bin NOT NULL DEFAULT 'vehicle',
      `contact_person_user_id` varchar(255) COLLATE utf8mb4_bin DEFAULT NULL,
      `vehicle_type` varchar(255) COLLATE utf8mb4_bin NOT NULL,
      `vehicle_make` varchar(255) COLLATE utf8mb4_bin NOT NULL,
      `vehicle_model` varchar(255) COLLATE utf8mb4_bin NOT NULL,
      `is_electric` tinyint(1) DEFAULT 0,
      `range` int(11) DEFAULT NULL,
      `seating_capacity` int(11) DEFAULT NULL,
      PRIMARY KEY (`id`),
      UNIQUE KEY `calresources_vehicles_uid` (`uid`),
      UNIQUE KEY `calresources_vehicles_eml` (`email`),
      KEY `calresources_vehicles_bid` (`building_id`),
      CONSTRAINT `FK_249B60A94D2A7E12` FOREIGN KEY (`building_id`) REFERENCES `calresources_buildings` (`id`) ON DELETE CASCADE
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;
    strozzascotte commented 1 year ago

    Hi, I have the same issue on Nextcloud Hub 3 (25.0.4).

    1. When I added the first room, it appeared in oc_calendars_roooms and a calendar for the room was created in oc_calendars. Everything worked.

    2. When I added a 2nd room, the 2nd room didn't appear in the oc_calendar_rooms table and no calendar was created for the room in oc_calendars.

    I hope it helps.

    ChristophWurst commented 1 year ago

    I don't think there even should be a calendar for a room or resource.

    meichthys commented 1 year ago

    I'm still seeing this issue on Calendar v4.3.4 and CalendarResourceManagement v0.5.0 The building/story/rooms do show via the terminal, and the cron job have definitely run: image

    sangdrax8 commented 1 year ago

    I have seen similar issues. I created 2 buildings, floors, and meeting rooms. These all showed up eventually (I didn't check it exactly 5 minutes after). I then decided to change my naming scheme and deleted the rooms, and then re-added with my new values. The calendar continues to show the old room names. I ran the cron to ensure it was run, I rebooted the box, nothing seemed to cause them to sync. I eventually went to the administration settings -> Basic Settings and switched it to AJAX syncing. I then went to the calendar and my new rooms were there. I then reverted the setting back to running with cron.

    This isn't a good solution, but since this is a testing instance it was ok for me. It seems the cron sync is an issue (or is it being to smart and choosing to not sync just because cron ran?)

    meichthys commented 1 year ago

    I can confirm that the resources did show up eventually even though i'm using cron - it just took longer than expected.

    kousu commented 1 year ago

    I am seeing this with

    • NC 25.0.9
    • Calendar 4.4.4
    • Calendar Resource Management 0.5.0

    I have these resources set up:

    calendar-resource:resources:list ``` www-data@org:~/nextcloud$ php occ calendar-resource:resources:list Buildings: +----+--------------+---------+--------------------------------------+-----------------------+ | ID | Name | Address | Description | Wheelchair Accessible | +----+--------------+---------+--------------------------------------+-----------------------+ | 2 | Bar | | | no | | 1 | Gear | | pool of gear and equipment | no | +----+--------------+---------+--------------------------------------+-----------------------+ Stories: +----+------------+-----------------+ | ID | Located in | Display Name | +----+------------+-----------------+ | 1 | Bar | Rez de Chaussee | +----+------------+-----------------+ Rooms: +----+---------+------+----------------------+-------------------------+-----------+----------------+----------+-------------+-------+--------------------+----+-----------+------------+-----------------------+ | ID | UID | Name | Located in | Email | Room Type | Contact Person | Capacity | Room Number | Phone | Video Conferencing | TV | Projector | Whiteboard | Wheelchair Accessible | +----+---------+------+----------------------+-------------------------+-----------+----------------+----------+-------------+-------+--------------------+----+-----------+------------+-----------------------+ | 1 | bar_rdc | Bar | Bar, Rez de Chaussee | admin+bar@example.org | salle | | 0 | | no | no | no | no | no | no | +----+---------+------+----------------------+-------------------------+-----------+----------------+----------+-------------+-------+--------------------+----+-----------+------------+-----------------------+ Resources: +----+----------------+-----------------------+----------------+----------------+----------------+ | ID | UID | Name | Located in | Contact Person | Type | +----+----------------+-----------------------+----------------+----------------+----------------+ | 1 | admin | Epson Projector | 1 Gear | | projector | | 2 | stripperpole | Stripper Pole | 1 Gear | | dance_pole | +----+----------------+-----------------------+----------------+----------------+----------------+ Vehicles: +----+-----+------+------------+-------+----------------+------+------+-------+----------+-------+----------+ | ID | UID | Name | Located in | Email | Contact Person | Type | Make | Model | Electric | Range | Capacity | +----+-----+------+------------+-------+----------------+------+------+-------+----------+-------+----------+ Restrictions: +----+--------+-----------+---------------+ | ID | Entity | Entity ID | Restricted To | +----+--------+-----------+---------------+ ```

    I'm using cron and it has run:

    2023-08-18-172202_1018x459_scrot

    But nothing shows when I search:

    2023-08-18-172237_1366x768_scrot


    I tried switching to "Background jobs = AJAX" like sangdrax8 suggested, but it didn't help.

    kousu commented 1 year ago

    I looked in the database, and found two tables, one of which is empty:

    MariaDB [nextcloud]> select * from oc_calresources_resources;
    +----+-------------+----------------+-----------------------+---------------------------------+----------------+------------------------+
    | id | building_id | uid            | display_name          | email                           | resource_type  | contact_person_user_id |
    +----+-------------+----------------+-----------------------+---------------------------------+----------------+------------------------+
    |  1 |           1 | projector1     | Epson Projector       | admin@example.org               | projector      |                        |
    |  4 |           1 | stripperpole   | Stripper Pole         | admin+stripperpole@example.org  | dance_pole     |                        |
    +----+-------------+----------------+-----------------------+---------------------------------+----------------+------------------------+
    5 rows in set (0.000 sec)
    
    MariaDB [nextcloud]> select * from oc_calendar_resources;
    Empty set (0.000 sec)
    MariaDB [nextcloud]> show create table oc_calendar_resources;
    +-----------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
    | Table                 | Create Table                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   |
    +-----------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
    | oc_calendar_resources | CREATE TABLE `oc_calendar_resources` (
      `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
      `backend_id` varchar(64) DEFAULT NULL,
      `resource_id` varchar(64) DEFAULT NULL,
      `email` varchar(255) DEFAULT NULL,
      `displayname` varchar(255) DEFAULT NULL,
      `group_restrictions` varchar(4000) DEFAULT NULL,
      PRIMARY KEY (`id`),
      KEY `calendar_resources_bkdrsc` (`backend_id`,`resource_id`),
      KEY `calendar_resources_email` (`email`),
      KEY `calendar_resources_name` (`displayname`)
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin |
    +-----------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

    So I think I see what's going on: oc_calresources_* are the tables managed by this plugin, but oc_calendar_resources is what hooks up the Calendar app to this plugin, and for some reason it's empty. I don't know why. It's like installing the plugin missed a step -- it should have registered itself, but it didn't.

    Does anyone know what backend_id should be? Is it 1? or calresources?

    I did

    MariaDB [nextcloud]> insert into oc_calendar_resources (backend_id, resource_id, email, displayname) values ("calresource", "stripperpole", "admin+stripperpole@example.org", "Stripper Pole");
    Query OK, 1 row affected (0.003 sec)

    and then it shows up in the Calendar search!

    2023-08-18-174523_1366x768_scrot

    but it doesn't work right, it can't confirm the availability nor book the item (presumably because I got backend_id or resource_id wrong)

    2023-08-18-174537_353x73_scrot


    I grepped around the code and found

    ./apps/dav/lib/BackgroundJob/UpdateCalendarResourcesRoomsBackgroundJob.php:         'calendar_resources',
    ./apps/dav/lib/BackgroundJob/UpdateCalendarResourcesRoomsBackgroundJob.php:         'calendar_resources_md',
    ./apps/dav/lib/CalDAV/Activity/Provider/Calendar.php:   public const SUBJECT_RESTORE = 'calendar_restore';
    ./apps/calendar_resource_management/lib/AppInfo/Application.php:    public const APP_ID = 'calendar_resource_management';

    I'm guessing backend_id == "calendar_resource_management", and that wherever the bug is it's in ./apps/dav/lib/BackgroundJob/UpdateCalendarResourcesRoomsBackgroundJob.php. If someone wants to investigate that file, have at it!

    kousu commented 1 year ago

    Hang on, I waited about 15 minutes, and now:

    MariaDB [nextcloud]> select * from oc_calendar_resources;
    +----+------------------------------+----------------+---------------------------------+-----------------------+--------------------+
    | id | backend_id                   | resource_id    | email                           | displayname           | group_restrictions |
    +----+------------------------------+----------------+---------------------------------+-----------------------+--------------------+
    |  1 | calresource                  | stripperpole   | admin+stripperpole@example.org  | Stripper Pole         | NULL               |
    |  2 | calendar_resource_management | admin          | admin@example.org               | Epson Projector       | []                 |
    |  3 | calendar_resource_management | stripperpole   | admin+stripperpole@example.org  | Stripper Pole         | []                 |
    +----+------------------------------+----------------+---------------------------------+-----------------------+--------------------+

    and it shows up in the UI:

    2023-08-18-183239_1366x768_scrot

    I deleted the one I hacked in

    MariaDB [nextcloud]> delete from oc_calendar_resources where backend_id = 'calresource';
    Query OK, 1 row affected (0.001 sec)

    and then I tried booking it again. It took, I guess, but it still doesn't seem to be able to successfully Check Availability:

    2023-08-18-174537_353x73_scrot


    So I don't know what's going on, but obviously UpdateCalendarResourcesRoomsBackgroundJob isn't actually being run according to the cron schedule.

    Do we know if there's a specific schedule? https://docs.nextcloud.com/server/latest/admin_manual/groupware/calendar.html#resources-and-rooms just says

    Nextcloud periodically queries all registered backends, therefore new/updated resources and rooms will show with a delay.

    which isn't very helpful for first time users.

    So @sangdrax8 and @derBobby, maybe what you did actually had no effect, except to slow down your efforts long enough that the background job could run and fill in oc_calendar_resources.

    christianlupus commented 11 months ago

    Just FYI, as I was affected by this: The background job only runs once an hour. So, you have to be patient when creating a new room.

    Djiock commented 6 months ago

    I'm having the same issue, a room created several days ago via cli (cron running fine) doesn't show up. I can see it in db though :

    select * from oc_calresources_rooms\G
    *************************** 1. row ***************************
                          id: 1
                    story_id: 1
                         uid: Salle 41
                display_name: Salle 41 Numérique
                       email: salle41.6p-nord-est@xxxxxx.org
                   room_type: Salle de réunion
      contact_person_user_id: 
                    capacity: 10
                 room_number: 41
                   has_phone: 0
      has_video_conferencing: 0
                      has_tv: 0
               has_projector: 0
              has_whiteboard: 0
    is_wheelchair_accessible: 0
    1 row in set (0.000 sec)
    

    No idea what could be missing... NC vers 28.0.4 App vers 0.7.0

    miaulalala commented 5 months ago

    This should ideally be updated to use some sort of event driven execution - either schedule a cron run as soon as possible when a room / resource has been added, or listen to an Event that is triggered on adding / updating a resource.

    st3iny commented 4 months ago

    Starting from Nextcloud 30, there will be instant updates of rooms and resources.

    Public OCP api: https://github.com/nextcloud/server/pull/45532 PR to implement it: #126

    st3iny commented 2 months ago

    Is done via #126 and will be part of the next minor release.