Migrate from Racoongang SCORM xblock to Overhangio SCORM xblock

Hi,
we have old native edX (Ironwood), which have 2 scorm xblocks:

openedx-scorm-xblock==10.0.1 (block_type=scorm) from https://github.com/overhangio/openedx-scorm-xblock
scormxblock-xblock==0.5 (block_type=scormxblock) from https://github.com/raccoongang/edx_xblock_scorm

We use both of them. So, before we upgrade our platform to Tutor, we need to migrate old scorm blocks (racoongang) to new (overhangio).
Let’s do it step by step

1. Mysql
Found scormxblock in 2 tables (db edxapp):

mysql> select * from completion_blockcompletion where block_type='scormxblock';
| created                    | modified                   | id    | course_key                      | block_key                                                                              | block_type  | completion | user_id |

| 2021-11-03 07:44:51.705637 | 2021-11-03 07:44:51.705954 | 35688 | course-v1:222+333+444           | block-v1:222+333+444+type@scormxblock+block@d3b7ca87eba54c3e8f441d317f9e6904           | scormxblock |     

mysql> select * from courseware_studentmodule where module_type='scormxblock';
| id    | module_type | module_id                                                                                         | course_id                                  | state                                                                                                                                                                                | grade | max_grade | done | created                    | modified                   | student_id |

| 52568 | scormxblock | block-v1:222+333+444+type@scormxblock+block@9363f5479472483793e7dceb01451ab1                      | course-v1:222+333+444                      | {"lesson_status": "incomplete"}                                                                                                                                                      |  NULL |      NULL | na   | 2021-11-02 12:48:27.213102 | 2021-11-02 12:48:27.213135 |         12 |

So, need to:

mysql> update completion_blockcompletion set block_type='scorm' where block_type='scormxblock';
mysql> update courseware_studentmodule set module_type='scorm' where module_type='scormxblock';

Besides, module_id and block_key need to be changed to use scorm instead of scormxblock in paths like block-v1:222+333+444+type@scormxblock+block@9363f5479472483793e7dceb01451ab1

===search for solution in progress===

2. Mongo
Found many of block_type=scormxblock (~1022) needed to be replaced to block_type=scorm


===search for solution in progress===

3. File store
We use django.core.files.storage.FileSystemStorage as default file storage.
So,
in /edx/var/edxapp/media/
both xblocks stores zip-files in

path/to/course/scormxblock/block_id/hash.zip (racoongang)
path/to/course/scorm/block_id/hash.zip (overhangio)

Maybe just copy block id’s in same courses from scormxblock to scorm folder?

Unpacked scorm stores like that:

[MEDIA_ROOT]/scorm/block_id/[index.html etc.] (racoongang)
[MEDIA_ROOT]/scorm/block_id/hash sha1/[index.html etc.] (overhangio)

So, we need to calculate every hash, make folder in scorm/block_id for it and move unpacked scorm.
===search for solution in progress===

Suppose, migrate procedures need to be merged in the script.
Any tips are appreciated!

So,
to clarify batch of old blocks (scormxblock) need to be recreate in fresh scorm block or migrate to, we use Coursegraph:

1. docker run --publish=7474:7474 --publish=7687:7687 --volume=$HOME/neo4j/data:/data neo4j:3.5.7 #this version is good for Ironwod (py2neo==3.1.2)
2. sudo -u www-data /edx/bin/python.edxapp ./manage.py lms dump_to_neo4j --host neo4j_server --http_port 7474 --user neo4j --password pass --settings production
3. ...and go for tea (in our case next day)

Now we got graph model for all courses. Some queries: https://openedx.atlassian.net/wiki/spaces/COMM/pages/3273228388/Useful+CourseGraph+Queries

In case of manual migrating (such re-creating fresh scorm blocks instead old one) we need to find all urls scormblocks:

MATCH
    (c:course) -[:PARENT_OF*]-> (v:vertical) -[:PARENT_OF*]-> (n:item)
WHERE
    c.course_key = 'course-v1:edX+DemoX+Demo_Course'
    AND
    n.block_type = 'scormxblock'
RETURN  
    n.block_type,
    n.display_name,
    n.location as block_id,
    v.display_name as unit_location,
    replace('https://your-edx/courses/course-id/jump_to_id/','course-id',c.course_key) + right(n.location, 32) as Unit_URL,
    n.edited_on, 
    n.visible_to_staff_only
ORDER BY
  n.edited_on;

So, we calculate time efforts and make decision to do some manual tasks.
To do this we need to be able to download zip-files from old scorm blocks.
Sorry for non-git, just took me a judge gaze pls)

in venvs/edxapp/lib/python2.7/site-packages/scormxblock/static/html/studio.html 
(and some static renders like staticfiles/studio/xblock/resources/scormxblock/static/html/studio.html and staticfiles/xblock/resources/scormxblock/static/html/studio.html)

edit Currently line like
      {% if scorm_xblock.scorm_file_meta.name %}
      <span class="tip setting-help setting-input-file"><span>{% trans "Currently:" %}</span> <a href="{{scorm_xblock.scorm_file_meta.path}}" download="{{scorm_xblock.scorm_file_meta.name}}">{{ scorm_xblock.scorm_file_meta.name }}</a></span>
      {% endif %}

Then in /etc/nginx/sites-enabled/cms add
  location ~ ^/container/.*/scormxblock/(.*\.zip) {
    root /edx/var/edxapp/media;
    rewrite /container/(.*\.zip) /$1 break;
  }

Nice.

Now we have csv-file with list of urls of all scorm blocks course by course (from Coursegraph + Neo4j). In some courses this mean to open over 300 links in browser to re-create scorm blocks.
So, we use url-opener.com to make this job a little bit easy.
Then, in studio view of every block we can download zip-file and upload this to new scorm block.
Brilliant, are we?

Not for students, who done this blocks already. All theys points will be erased in this manual scorm migration process.

And neo4j query for make list of courses, who really uses old scorm block:

MATCH 
	(c:course)-[:PARENT_OF*]->(p:scormxblock)
RETURN 
	distinct(p.course_key), 
	count(distinct(p)), 
	c.start, 
	c.end 
order by 
	c.start desc