Documentation

Introduction

Attention! We strongly recommend first to learn more about REST documentation for the Sites module to understand module operation principles (as well as available REST in Bitrix24 Self-hosted edition). View this documentation as auxiliary resource of information when working with Bitrix24 Self-hosted, when just REST features are not enough and you want to get more details for API.

Sites24 files are stored in the table b_file and are interacted with via the class CFile. Also, an additional API is available, tracking the number of "references" to a file.

To better understand the necessity of additional API, let's take a look at information blocks. For example, when you add an image into a block. It is a single entry in the table b_file. Because this block was copied, two entries now exist. Now, the page is copied and there are three entries (for this page). And now, let's delete the very first block. In this case, API controls, are there any more references to this file? If no, it deletes the file on the drive via CFile::delete. Otherwise, there won't be any physical deleting.

When deleting an entity (for example, block), file is not deleted immediately it will be marked as deleted and only system agent will analyze the status later and will delete the file. This process is implemented for optimization.

The above example is provided for a block. The system behaves in the similar manner with pages and even sites. They can have their own images. For example, a background image, image from social networks, and etc.

For the system to understand where a file is located inside a block, each image-containing node is automatically marked by data-fileid and data-fileid2x data attributes, where file ID is directly stored for standard version and for image retina version.

The system analyses all this data automatically, so no action is required from the developer. Here are some examples. All methods does not return a result except for direct getter methods.

if (\Bitrix\Main\Loader::includeModule('landing'))
{
   // file ID from the table b_file
   $fileId = 123;
   // add file to site with ID=1
   Bitrix\Landing\File::addToSite(1, $fileId);
   // delete file (or file array) from site with ID=1
   Bitrix\Landing\File::deleteFromSite(1, $fileId);
   // add file to page with ID=1
   Bitrix\Landing\File::addToLanding(1, $fileId);
   // delete file (or file array) from page with ID=1
   Bitrix\Landing\File::deleteFromLanding(1, $fileId);
   // add file to block with ID=1
   Bitrix\Landing\File::addToBlock(1, $fileId);
   // delete file (or array of files) from block with ID=1
   Bitrix\Landing\File::deleteFromBlock(1, $fileId);
   // replace file (or array of files) in block with ID=1 (old file associations will be deleted)
   Bitrix\Landing\File::replaceInBlock(1, $fileId);
   // get array of files from text $content (data-fileid attributes)
   Bitrix\Landing\File::getFilesFromBlockContent(1, $content);
   // copies block files to another block
   Bitrix\Landing\File::copyBlockFiles(1, 2);
   // final cleaner that checks files marked for deletion and deletes files
   Bitrix\Landing\File::deleteFinal(30);
   // get list of all file IDs from block with ID=1
   Bitrix\Landing\File::getFilesFromBlock(1);
   // get list of all files IDs from landing page with ID=1
   Bitrix\Landing\File::getFilesFromLanding(1);
   // get list of all file IDs from site with ID=1
   Bitrix\Landing\File::getFilesFromSite(1);
}


© «Bitrix24», 2001-2024
Up