{"action":"created","comment":{"url":"https://api.github.com/repos/ezsystems/ezpublish-legacy/pulls/comments/40999107","id":40999107,"diff_hunk":"@@ -0,0 +1,249 @@\n+<?php\n+/**\n+ * File containing the cleanupfieldvaluerelations.php script\n+ *\n+ * @copyright Copyright (C) eZ Systems AS. All rights reserved.\n+ * @license For full copyright and license information view LICENSE file distributed with this source code.\n+ * @version //autogentag//\n+ */\n+\n+require_once 'autoload.php';\n+\n+$cli = eZCLI::instance();\n+\n+$script = eZScript::instance(\n+    array(\n+        'description' => \"Removes relation data towards non-existing Content from field values.\\n\" .\n+            \"Only Relation and RelationList fieldtypes field values will be processed.\\n\" .\n+            \"For more details see https://jira.ez.no/browse/EZP-22408.\",\n+        'use-session' => false,\n+        'use-modules' => false,\n+        'use-extensions' => true\n+    )\n+);\n+$script->startup();\n+\n+$options = $script->getOptions(\n+    \"[n][v][iteration-sleep:][iteration-limit:]\",\n+    \"\",\n+    array(\n+        'iteration-sleep' => 'Sleep duration between batches, in seconds (default: 1)',\n+        'iteration-limit' => 'Batch size (default: 100)',\n+        'n' => 'Do not wait 30 seconds before starting',\n+    )\n+);\n+$optIterationSleep = (int)$options['iteration-sleep'] ?: 1;\n+$optIterationLimit = (int)$options['iteration-limit'] ?: 100;\n+$verboseLevel = $script->verboseOutputLevel();\n+\n+$script->initialize();\n+\n+$db = eZDB::instance();\n+\n+if ( !$db->isConnected() )\n+{\n+    $cli->error( \"Can't initialize database connection.\\n\" );\n+    $script->shutdown( 1 );\n+}\n+\n+$relationCount = $result = $db->arrayQuery(\n+    \"SELECT ( COUNT( * ) ) AS relation_count\n+     FROM ezcontentobject_attribute\n+     LEFT JOIN ezcontentobject ON ezcontentobject_attribute.data_int = ezcontentobject.id\n+     WHERE ezcontentobject_attribute.data_type_string = 'ezobjectrelation' AND\n+           ezcontentobject_attribute.data_int IS NOT NULL AND\n+           ezcontentobject.id IS NULL\"\n+);\n+$relationCount = $relationCount[0][\"relation_count\"];\n+\n+$relationListCount = $result = $db->arrayQuery(\n+    \"SELECT ( COUNT( * ) ) AS relationlist_count\n+     FROM ezcontentobject_attribute\n+     WHERE ezcontentobject_attribute.data_type_string = 'ezobjectrelationlist'\"\n+);\n+$relationListCount = $relationListCount[0][\"relationlist_count\"];\n+\n+$cli->warning( \"This script removes relation data towards non-existing Content from field values.\" );\n+$cli->warning( \"Only Relation and RelationList fieldtypes field values will be processed.\" );\n+$cli->warning( \"For more details about this cleanup, see https://jira.ez.no/browse/EZP-22408.\" );\n+$cli->output();\n+$cli->output( \"Found total of {$relationCount} Relation and {$relationListCount} RelationList field values to process.\" );\n+\n+if ( $relationCount == 0 && $relationListCount == 0 )\n+{\n+    $cli->output( \"Nothing to process, exiting.\" );\n+    $script->shutdown( 0 );\n+}\n+\n+$cli->output();\n+$cli->output( \"Relation field values will be updated in a single update\" );\n+$cli->output( \"RelationList field values will be processed in batches of {$optIterationLimit}, with {$optIterationSleep} seconds pause between the batches.\" );\n+$cli->warning( \"Depending on the number of RelationList field values found, this script can potentially run for a very long time.\" );\n+\n+if ( !$options['n'] )\n+{\n+    $cli->output();\n+    $cli->warning( \"You have 30 seconds to break the script before actual processing starts (press Ctrl-C).\" );\n+    $cli->warning( \"Execute the script with '-n' switch to skip this delay.\" );\n+    sleep( 30 );\n+}\n+\n+function processRelationRows()\n+{\n+    global $db, $cli, $relationCount;","path":"update/common/scripts/5.4/cleanupfieldvaluerelations.php","position":93,"original_position":93,"commit_id":"880598ea9c28841b13750bd61be0914938a47b3a","original_commit_id":"880598ea9c28841b13750bd61be0914938a47b3a","user":{"login":"emodric","id":362286,"avatar_url":"https://avatars.githubusercontent.com/u/362286?v=3","gravatar_id":"","url":"https://api.github.com/users/emodric","html_url":"https://github.com/emodric","followers_url":"https://api.github.com/users/emodric/followers","following_url":"https://api.github.com/users/emodric/following{/other_user}","gists_url":"https://api.github.com/users/emodric/gists{/gist_id}","starred_url":"https://api.github.com/users/emodric/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/emodric/subscriptions","organizations_url":"https://api.github.com/users/emodric/orgs","repos_url":"https://api.github.com/users/emodric/repos","events_url":"https://api.github.com/users/emodric/events{/privacy}","received_events_url":"https://api.github.com/users/emodric/received_events","type":"User","site_admin":false},"body":"Isn't this gonna cause issues when running through ezpublish:legacy:script?\r\n\r\nRef: https://jira.ez.no/browse/EZP-21913","created_at":"2015-10-02T08:05:56Z","updated_at":"2015-10-02T08:05:56Z","html_url":"https://github.com/ezsystems/ezpublish-legacy/pull/1074#discussion_r40999107","pull_request_url":"https://api.github.com/repos/ezsystems/ezpublish-legacy/pulls/1074","_links":{"self":{"href":"https://api.github.com/repos/ezsystems/ezpublish-legacy/pulls/comments/40999107"},"html":{"href":"https://github.com/ezsystems/ezpublish-legacy/pull/1074#discussion_r40999107"},"pull_request":{"href":"https://api.github.com/repos/ezsystems/ezpublish-legacy/pulls/1074"}}},"pull_request":{"url":"https://api.github.com/repos/ezsystems/ezpublish-legacy/pulls/1074","id":21243781,"html_url":"https://github.com/ezsystems/ezpublish-legacy/pull/1074","diff_url":"https://github.com/ezsystems/ezpublish-legacy/pull/1074.diff","patch_url":"https://github.com/ezsystems/ezpublish-legacy/pull/1074.patch","issue_url":"https://api.github.com/repos/ezsystems/ezpublish-legacy/issues/1074","number":1074,"state":"closed","locked":false,"title":"Fix EZP-22408: Deleting a content does not remove references to this content in relation(list) fields","user":{"login":"pspanja","id":1135425,"avatar_url":"https://avatars.githubusercontent.com/u/1135425?v=3","gravatar_id":"","url":"https://api.github.com/users/pspanja","html_url":"https://github.com/pspanja","followers_url":"https://api.github.com/users/pspanja/followers","following_url":"https://api.github.com/users/pspanja/following{/other_user}","gists_url":"https://api.github.com/users/pspanja/gists{/gist_id}","starred_url":"https://api.github.com/users/pspanja/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pspanja/subscriptions","organizations_url":"https://api.github.com/users/pspanja/orgs","repos_url":"https://api.github.com/users/pspanja/repos","events_url":"https://api.github.com/users/pspanja/events{/privacy}","received_events_url":"https://api.github.com/users/pspanja/received_events","type":"User","site_admin":false},"body":"This PR resolves issue https://jira.ez.no/browse/EZP-22408\r\n\r\nThis implements cleanup script.\r\nFor more details see `ezpublish-kernel` PR for the same issue at https://github.com/ezsystems/ezpublish-kernel/pull/993.","created_at":"2014-09-15T16:33:50Z","updated_at":"2015-10-02T08:05:56Z","closed_at":"2015-09-30T13:20:54Z","merged_at":"2015-09-30T13:20:54Z","merge_commit_sha":"c62243a9b115b556c8572a54a66ae4c3101605e2","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/ezsystems/ezpublish-legacy/pulls/1074/commits","review_comments_url":"https://api.github.com/repos/ezsystems/ezpublish-legacy/pulls/1074/comments","review_comment_url":"https://api.github.com/repos/ezsystems/ezpublish-legacy/pulls/comments{/number}","comments_url":"https://api.github.com/repos/ezsystems/ezpublish-legacy/issues/1074/comments","statuses_url":"https://api.github.com/repos/ezsystems/ezpublish-legacy/statuses/880598ea9c28841b13750bd61be0914938a47b3a","head":{"label":"ezsystems:fix-EZP-22408-relation-ref","ref":"fix-EZP-22408-relation-ref","sha":"880598ea9c28841b13750bd61be0914938a47b3a","user":{"login":"ezsystems","id":295311,"avatar_url":"https://avatars.githubusercontent.com/u/295311?v=3","gravatar_id":"","url":"https://api.github.com/users/ezsystems","html_url":"https://github.com/ezsystems","followers_url":"https://api.github.com/users/ezsystems/followers","following_url":"https://api.github.com/users/ezsystems/following{/other_user}","gists_url":"https://api.github.com/users/ezsystems/gists{/gist_id}","starred_url":"https://api.github.com/users/ezsystems/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ezsystems/subscriptions","organizations_url":"https://api.github.com/users/ezsystems/orgs","repos_url":"https://api.github.com/users/ezsystems/repos","events_url":"https://api.github.com/users/ezsystems/events{/privacy}","received_events_url":"https://api.github.com/users/ezsystems/received_events","type":"Organization","site_admin":false},"repo":{"id":715911,"name":"ezpublish-legacy","full_name":"ezsystems/ezpublish-legacy","owner":{"login":"ezsystems","id":295311,"avatar_url":"https://avatars.githubusercontent.com/u/295311?v=3","gravatar_id":"","url":"https://api.github.com/users/ezsystems","html_url":"https://github.com/ezsystems","followers_url":"https://api.github.com/users/ezsystems/followers","following_url":"https://api.github.com/users/ezsystems/following{/other_user}","gists_url":"https://api.github.com/users/ezsystems/gists{/gist_id}","starred_url":"https://api.github.com/users/ezsystems/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ezsystems/subscriptions","organizations_url":"https://api.github.com/users/ezsystems/orgs","repos_url":"https://api.github.com/users/ezsystems/repos","events_url":"https://api.github.com/users/ezsystems/events{/privacy}","received_events_url":"https://api.github.com/users/ezsystems/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/ezsystems/ezpublish-legacy","description":"eZ Publish","fork":false,"url":"https://api.github.com/repos/ezsystems/ezpublish-legacy","forks_url":"https://api.github.com/repos/ezsystems/ezpublish-legacy/forks","keys_url":"https://api.github.com/repos/ezsystems/ezpublish-legacy/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ezsystems/ezpublish-legacy/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ezsystems/ezpublish-legacy/teams","hooks_url":"https://api.github.com/repos/ezsystems/ezpublish-legacy/hooks","issue_events_url":"https://api.github.com/repos/ezsystems/ezpublish-legacy/issues/events{/number}","events_url":"https://api.github.com/repos/ezsystems/ezpublish-legacy/events","assignees_url":"https://api.github.com/repos/ezsystems/ezpublish-legacy/assignees{/user}","branches_url":"https://api.github.com/repos/ezsystems/ezpublish-legacy/branches{/branch}","tags_url":"https://api.github.com/repos/ezsystems/ezpublish-legacy/tags","blobs_url":"https://api.github.com/repos/ezsystems/ezpublish-legacy/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ezsystems/ezpublish-legacy/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ezsystems/ezpublish-legacy/git/refs{/sha}","trees_url":"https://api.github.com/repos/ezsystems/ezpublish-legacy/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ezsystems/ezpublish-legacy/statuses/{sha}","languages_url":"https://api.github.com/repos/ezsystems/ezpublish-legacy/languages","stargazers_url":"https://api.github.com/repos/ezsystems/ezpublish-legacy/stargazers","contributors_url":"https://api.github.com/repos/ezsystems/ezpublish-legacy/contributors","subscribers_url":"https://api.github.com/repos/ezsystems/ezpublish-legacy/subscribers","subscription_url":"https://api.github.com/repos/ezsystems/ezpublish-legacy/subscription","commits_url":"https://api.github.com/repos/ezsystems/ezpublish-legacy/commits{/sha}","git_commits_url":"https://api.github.com/repos/ezsystems/ezpublish-legacy/git/commits{/sha}","comments_url":"https://api.github.com/repos/ezsystems/ezpublish-legacy/comments{/number}","issue_comment_url":"https://api.github.com/repos/ezsystems/ezpublish-legacy/issues/comments{/number}","contents_url":"https://api.github.com/repos/ezsystems/ezpublish-legacy/contents/{+path}","compare_url":"https://api.github.com/repos/ezsystems/ezpublish-legacy/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ezsystems/ezpublish-legacy/merges","archive_url":"https://api.github.com/repos/ezsystems/ezpublish-legacy/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ezsystems/ezpublish-legacy/downloads","issues_url":"https://api.github.com/repos/ezsystems/ezpublish-legacy/issues{/number}","pulls_url":"https://api.github.com/repos/ezsystems/ezpublish-legacy/pulls{/number}","milestones_url":"https://api.github.com/repos/ezsystems/ezpublish-legacy/milestones{/number}","notifications_url":"https://api.github.com/repos/ezsystems/ezpublish-legacy/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ezsystems/ezpublish-legacy/labels{/name}","releases_url":"https://api.github.com/repos/ezsystems/ezpublish-legacy/releases{/id}","created_at":"2010-06-11T15:47:13Z","updated_at":"2015-08-04T07:18:09Z","pushed_at":"2015-09-30T16:54:08Z","git_url":"git://github.com/ezsystems/ezpublish-legacy.git","ssh_url":"git@github.com:ezsystems/ezpublish-legacy.git","clone_url":"https://github.com/ezsystems/ezpublish-legacy.git","svn_url":"https://github.com/ezsystems/ezpublish-legacy","homepage":"http://ez.no/Products/","size":318009,"stargazers_count":259,"watchers_count":259,"language":"JavaScript","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":233,"mirror_url":null,"open_issues_count":157,"forks":233,"open_issues":157,"watchers":259,"default_branch":"master"}},"base":{"label":"ezsystems:master","ref":"master","sha":"24108d401e66ccb3844721ae2a1cf04d6213a532","user":{"login":"ezsystems","id":295311,"avatar_url":"https://avatars.githubusercontent.com/u/295311?v=3","gravatar_id":"","url":"https://api.github.com/users/ezsystems","html_url":"https://github.com/ezsystems","followers_url":"https://api.github.com/users/ezsystems/followers","following_url":"https://api.github.com/users/ezsystems/following{/other_user}","gists_url":"https://api.github.com/users/ezsystems/gists{/gist_id}","starred_url":"https://api.github.com/users/ezsystems/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ezsystems/subscriptions","organizations_url":"https://api.github.com/users/ezsystems/orgs","repos_url":"https://api.github.com/users/ezsystems/repos","events_url":"https://api.github.com/users/ezsystems/events{/privacy}","received_events_url":"https://api.github.com/users/ezsystems/received_events","type":"Organization","site_admin":false},"repo":{"id":715911,"name":"ezpublish-legacy","full_name":"ezsystems/ezpublish-legacy","owner":{"login":"ezsystems","id":295311,"avatar_url":"https://avatars.githubusercontent.com/u/295311?v=3","gravatar_id":"","url":"https://api.github.com/users/ezsystems","html_url":"https://github.com/ezsystems","followers_url":"https://api.github.com/users/ezsystems/followers","following_url":"https://api.github.com/users/ezsystems/following{/other_user}","gists_url":"https://api.github.com/users/ezsystems/gists{/gist_id}","starred_url":"https://api.github.com/users/ezsystems/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ezsystems/subscriptions","organizations_url":"https://api.github.com/users/ezsystems/orgs","repos_url":"https://api.github.com/users/ezsystems/repos","events_url":"https://api.github.com/users/ezsystems/events{/privacy}","received_events_url":"https://api.github.com/users/ezsystems/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/ezsystems/ezpublish-legacy","description":"eZ Publish","fork":false,"url":"https://api.github.com/repos/ezsystems/ezpublish-legacy","forks_url":"https://api.github.com/repos/ezsystems/ezpublish-legacy/forks","keys_url":"https://api.github.com/repos/ezsystems/ezpublish-legacy/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ezsystems/ezpublish-legacy/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ezsystems/ezpublish-legacy/teams","hooks_url":"https://api.github.com/repos/ezsystems/ezpublish-legacy/hooks","issue_events_url":"https://api.github.com/repos/ezsystems/ezpublish-legacy/issues/events{/number}","events_url":"https://api.github.com/repos/ezsystems/ezpublish-legacy/events","assignees_url":"https://api.github.com/repos/ezsystems/ezpublish-legacy/assignees{/user}","branches_url":"https://api.github.com/repos/ezsystems/ezpublish-legacy/branches{/branch}","tags_url":"https://api.github.com/repos/ezsystems/ezpublish-legacy/tags","blobs_url":"https://api.github.com/repos/ezsystems/ezpublish-legacy/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ezsystems/ezpublish-legacy/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ezsystems/ezpublish-legacy/git/refs{/sha}","trees_url":"https://api.github.com/repos/ezsystems/ezpublish-legacy/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ezsystems/ezpublish-legacy/statuses/{sha}","languages_url":"https://api.github.com/repos/ezsystems/ezpublish-legacy/languages","stargazers_url":"https://api.github.com/repos/ezsystems/ezpublish-legacy/stargazers","contributors_url":"https://api.github.com/repos/ezsystems/ezpublish-legacy/contributors","subscribers_url":"https://api.github.com/repos/ezsystems/ezpublish-legacy/subscribers","subscription_url":"https://api.github.com/repos/ezsystems/ezpublish-legacy/subscription","commits_url":"https://api.github.com/repos/ezsystems/ezpublish-legacy/commits{/sha}","git_commits_url":"https://api.github.com/repos/ezsystems/ezpublish-legacy/git/commits{/sha}","comments_url":"https://api.github.com/repos/ezsystems/ezpublish-legacy/comments{/number}","issue_comment_url":"https://api.github.com/repos/ezsystems/ezpublish-legacy/issues/comments{/number}","contents_url":"https://api.github.com/repos/ezsystems/ezpublish-legacy/contents/{+path}","compare_url":"https://api.github.com/repos/ezsystems/ezpublish-legacy/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ezsystems/ezpublish-legacy/merges","archive_url":"https://api.github.com/repos/ezsystems/ezpublish-legacy/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ezsystems/ezpublish-legacy/downloads","issues_url":"https://api.github.com/repos/ezsystems/ezpublish-legacy/issues{/number}","pulls_url":"https://api.github.com/repos/ezsystems/ezpublish-legacy/pulls{/number}","milestones_url":"https://api.github.com/repos/ezsystems/ezpublish-legacy/milestones{/number}","notifications_url":"https://api.github.com/repos/ezsystems/ezpublish-legacy/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ezsystems/ezpublish-legacy/labels{/name}","releases_url":"https://api.github.com/repos/ezsystems/ezpublish-legacy/releases{/id}","created_at":"2010-06-11T15:47:13Z","updated_at":"2015-08-04T07:18:09Z","pushed_at":"2015-09-30T16:54:08Z","git_url":"git://github.com/ezsystems/ezpublish-legacy.git","ssh_url":"git@github.com:ezsystems/ezpublish-legacy.git","clone_url":"https://github.com/ezsystems/ezpublish-legacy.git","svn_url":"https://github.com/ezsystems/ezpublish-legacy","homepage":"http://ez.no/Products/","size":318009,"stargazers_count":259,"watchers_count":259,"language":"JavaScript","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":233,"mirror_url":null,"open_issues_count":157,"forks":233,"open_issues":157,"watchers":259,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/ezsystems/ezpublish-legacy/pulls/1074"},"html":{"href":"https://github.com/ezsystems/ezpublish-legacy/pull/1074"},"issue":{"href":"https://api.github.com/repos/ezsystems/ezpublish-legacy/issues/1074"},"comments":{"href":"https://api.github.com/repos/ezsystems/ezpublish-legacy/issues/1074/comments"},"review_comments":{"href":"https://api.github.com/repos/ezsystems/ezpublish-legacy/pulls/1074/comments"},"review_comment":{"href":"https://api.github.com/repos/ezsystems/ezpublish-legacy/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/ezsystems/ezpublish-legacy/pulls/1074/commits"},"statuses":{"href":"https://api.github.com/repos/ezsystems/ezpublish-legacy/statuses/880598ea9c28841b13750bd61be0914938a47b3a"}}}}