Hello.
The file table has an unique index on the shortUrl field. This field is filled with the string 'temp' by the moveIntoStorage function in the file class. The script doesn't use transactions but mysql queries are atomic. When 2 files are being processed at the same time, one of them will manage to make a insert with shortUrl = 'temp'. The second file will try to insert a new row with shortUrl = 'temp' before the first file manage to create the correct shortUrl and the insert will fail because the index doesn't allow 2 rows with shortUrl = 'temp'.
Also, this is how the script checks the insert: if (!$dbInsert->insert()). If you look at the insert function you will see that it tries to execute the insert and them returns the last inserted id. But this last inserted id isn't necessarily from the last insert that wasn't successful. If the insert fails it will return another id from another insert executed earlier.
This error is not easy to reproduce. It took me all morning to find it.
The file table has an unique index on the shortUrl field. This field is filled with the string 'temp' by the moveIntoStorage function in the file class. The script doesn't use transactions but mysql queries are atomic. When 2 files are being processed at the same time, one of them will manage to make a insert with shortUrl = 'temp'. The second file will try to insert a new row with shortUrl = 'temp' before the first file manage to create the correct shortUrl and the insert will fail because the index doesn't allow 2 rows with shortUrl = 'temp'.
Also, this is how the script checks the insert: if (!$dbInsert->insert()). If you look at the insert function you will see that it tries to execute the insert and them returns the last inserted id. But this last inserted id isn't necessarily from the last insert that wasn't successful. If the insert fails it will return another id from another insert executed earlier.
This error is not easy to reproduce. It took me all morning to find it.