agentejo / cockpit

Add content management functionality to any site - plug & play / headless / api-first CMS
http://getcockpit.com
MIT License
5.39k stars 522 forks source link

mongo fatal error on collections #967

Open AKApumkin opened 5 years ago

AKApumkin commented 5 years ago

When using integers on the name, group and label fields, e.g. 1, 2, 3 it causes the following error:

Oh no! Something went terribly wrong: Call to a member function fetch() on boolean

The only way to restore is a clean wipe.

pauloamgomes commented 5 years ago

Hey @AKApumkin , can you detail better the issue? You mean inserting only a number in a collection type (field name, group or label)? It seems to work well on next branch!

AKApumkin commented 5 years ago

collection db_error

pauloamgomes commented 5 years ago

Yeah, I don't have the same behaviour as you (using 0.8.7 mongodb) when creating:

image

But then I'm unable for example to remove the collection in the ui, need to delete it manually by removing the corresponding file in storage/collections/1.php

aheinze commented 5 years ago

@AKApumkin you're using MongoLite not MongoDb. I'll investigate this.

AKApumkin commented 5 years ago

Looks like that might be the issue with Mongo, im using the latest from docker, i have attached my docker-compose.yml

separately i managed to fix it by adding a pattern to the view on those fields that prohibits 0-9. However i'm still trying to figure out how the persistent data from the cockpit container can be stored in a volumes, so in the event of a restart, this fix and all subsequent changes are persistent.

version: '3'
services:
  db:
    image: 'mongo:latest'
    volumes:
      - './mongo-vol:/data/db'
    networks:
      - my_net
  cms:
    image: agentejo/cockpit
    environment:
      COCKPIT_SESSION_NAME: cockpit
      COCKPIT_SALT: my_salt
      COCKPIT_DATABASE_SERVER: 'mongodb://db:27017'
      COCKPIT_DATABASE_NAME: my_db
    depends_on:
      - db
    ports: 
      - "8080:80"
    networks:
      - my_net
networks:
  my_net:
    driver: bridge
bsgdigital commented 5 years ago

I ran into the same issue even though I'm not using Mongo at all. Steps to recreate:

  1. Use latest image from docker with default settings
  2. Create collection named "1" as an example
  3. Go to admin home URL

The following error is displayed

Fatal error: Uncaught Error: Call to a member function fetch() on boolean in /var/www/html/lib/MongoLite/Cursor.php:86 Stack trace: #0 /var/www/html/lib/MongoLite/Collection.php(159): MongoLite\Cursor->count() #1 /var/www/html/lib/MongoHybrid/MongoLite.php(76): MongoLite\Collection->count(Array) #2 [internal function]: MongoHybrid\MongoLite->count('collections/15c...', Array) #3 /var/www/html/lib/MongoHybrid/Client.php(420): call_user_func_array(Array, Array) #4 /var/www/html/modules/Collections/bootstrap.php(427): MongoHybrid\Client->__call('count', Array) #5 [internal function]: Lime\Module->{closure}('15c4afbfc079c2') #6 /var/www/html/lib/Lime/App.php(1483): call_user_func_array(Object(Closure), Array) #7 /var/www/html/modules/Collections/bootstrap.php(133): Lime\Module->__call('count', Array) #8 [internal function]: Lime\Module->{closure}(true) #9 /var/www/html/lib/Lime/App.php(1483): call_user_func_array(Object(Closure), Array) #10 /var/www/html/modules/Collections/bootstrap.php(661): Lime\Module->__call('collections in /var/www/html/lib/MongoLite/Cursor.php on line 86

The only way to resolve is to remove the collection from /var/www/html/storage/collections

Also, similar problem occurs when you create collection with hyphen in it (HTML5 validation in Safari allows it to happen when saved with hotkey)