0

I'm working on application based on Drupal 7.39 that use the Storage Api module version 7.x-1.8 with FTP container.

I'm trying to achieve is to remove this module and use the normal flow to save assets (I think that all assets will be saved in app/sites/default/files).

I downloaded all files from FTP container in app/sites/default/files folder.

I tried to disable the module, but I noticed that images fields served by the plugin are not available anymore. The association in content pages are still present but I only see a broken link.

How can I update all the fields served by the plugin to use files that are in app/sites/default/files? In other words I want to remove the plugin and all his associations to files. Is that possible? Can I migrate these associations?

Thank you.

UPDATE

As Jonathan Rhodes suggests me, here's the procedure to update uris.

$queryString = "SELECT * FROM db.file_managed WHERE uri REGEXP '^storage-a*'";

try {
    $db = new PDO("mysql:host=localhost;dbname=db;charset=utf8", "root", "root");
    $query = $db->prepare($queryString);
    $query->execute();

    $rows = $query->fetchAll(PDO::FETCH_ASSOC);

    $func = function ($element) use ($db) {
        $uri = $element['uri'];
        $uriReplaced = preg_replace('/^(storage-.*)(:\/\/.*)/', "public$2", $uri);
        $queryUpdate = "UPDATE db.file_managed SET uri = :uri WHERE fid = :fid";
        $query = $db->prepare($queryUpdate);
        $query->execute(['uri' => $uriReplaced, 'fid' => (int) $element['fid']]);
    };

    echo count($rows);
    array_map($func, $rows);
} catch (PDOException  $e) {
    echo "Error: " . $e;
}

echo 'ok';
0

You'll probably need to manually update the files_managed database table and change the uri to use the public:// schema.

  • Yes, you totally right! I update my answer to add the procedure, maybe it helps someone in future! – stuzzo Apr 13 '17 at 15:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.