output(); // check local folder path exists if (!file_exists(FILE_IMPORT_PATH)) { $pluginObj->output('ERROR: Local file path not found: ' . FILE_IMPORT_PATH, true); } // make sure account exists if (!$user = User::loadOneByClause('username = :username', array( 'username' => FILE_IMPORT_ACCOUNT_NAME, ))) { $pluginObj->output('ERROR: User account not found: ' . FILE_IMPORT_ACCOUNT_NAME, true); } // set user id for later define('FILE_IMPORT_ACCOUNT_USER_ID', $user->id); // make sure the folder id exists on the account $folderId = 0; if (FILE_IMPORT_ACCOUNT_START_FOLDER != null) { $folder = $db->getRow('SELECT * ' . 'FROM file_folder ' . 'WHERE userId = :user_id ' . 'AND folderName = :folder_name ' . 'AND parentId IS NULL ' . 'AND status = "active" ' . 'LIMIT 1', array( 'user_id' => (int)FILE_IMPORT_ACCOUNT_USER_ID, 'folder_name' => FILE_IMPORT_ACCOUNT_START_FOLDER, )); if (!$folder) { $pluginObj->output('ERROR: Could not load folder: ' . FILE_IMPORT_ACCOUNT_START_FOLDER, true); } else { if ($folder['userId'] != $user->id) { $pluginObj->output('ERROR: Folder does not belong to that user: ' . FILE_IMPORT_ACCOUNT_START_FOLDER, true); } } $folderId = $folder['id']; } // prepare folder id if ((int) $folderId == 0) { $folderId = null; } // prepare path $localPath = FILE_IMPORT_PATH; if (substr($localPath, strlen($localPath) - 1, 1) != '/') { $localPath .= '/'; } // scan for files $items = CoreHelper::getDirectoryListing($localPath); if (count($items) == 0) { $pluginObj->output('ERROR: No files or folders found in folder. Total: ' . COUNT($items), true); } // import files $pluginObj->importFiles($localPath, FILE_IMPORT_ACCOUNT_USER_ID, $folderId); // finish $pluginObj->output('Import process completed.');